我的代码是这样的,不知道是哪个地方有问题
//== [将String存入DataSet]
procedure TwwMcciQuery.ReadResultToDataset(sResult: string);
var
I: Integer;
TempLine: TStringListEx;
temp:string;
iFieldID: Integer;
sForward, sBackward: String;
begin
if Trim(sResult) = '' then
Exit;
// 将数据包按行存入数组
TempLine:= TStringListEx.Create;
TempLine.Splitter:= LINE_END;
TempLine.SetCharText(sResult);
TempLine.SaveToFile('c:/aaaa.txt');
try
Close;
DisableControls;
// 前三行用于存字段定义(名称、类型)
SetFieldDefs(TempLine, FieldDefs);
inherited Open;
// 第四行(TempLine[3])起用于存字段值
if TempLine.Count > LINE_VALUE then
begin
for I:= LINE_VALUE to TempLine.Count-1 do
begin
Append;
iFieldID:= 0;
sBackward:= TempLine;
repeat
sForward:= GetFirstToken(sBackward, FIELD_END);
Fields[iFieldID].AsString:= sForward;
sBackward:= StripFirstToken(sBackward, FIELD_END);
inc(iFieldID);
until
(sBackward = '');
post;
end;
First;
end;
finally
TempLine.Free;
EnableControls;
end;
end;
//== [第二、三行用于存字段定义(名称、类型)]
procedure SetFieldDefs(Lines: TStrings; FieldDefs: TFieldDefs);
var
I: Integer;
sFieldName, sFieldNameLine, sFieldType, sFieldTypeLine: String;
begin
I:= 0;
sFieldNameLine:= Lines[1]; // 第二行: 字段名称 (第一行: 字段数目)
sFieldTypeLine:= Lines[2]; // 第三行: 字段类型
FieldDefs.Clear;
repeat
// 第二行: 字段名称
sFieldName:= GetFirstToken(sFieldNameLine, FIELD_END);
sFieldNameLine:= StripFirstToken(sFieldNameLine, FIELD_END);
// 第三行: 字段类型
sFieldType:= GetFirstToken(sFieldTypeLine, FIELD_END);
if sFieldType='DATE_TYPE' Then
FieldDefs.Add(sFieldName, ftDateTime)
else if sFieldType='FLOAT_TYPE' Then
FieldDefs.Add(sFieldName, ftFloat)
else if sFieldType='INT_TYPE' Then
FieldDefs.Add(sFieldName, ftFloat)
else
FieldDefs.Add(sFieldName, ftString, 250);
sFieldTypeLine:= StripFirstToken(sFieldTypeLine, FIELD_END);
Inc(I);
until
(sFieldNameLine = '');
end;