Delphi5 代码转 C++ Builder5-6,请各位跨越这个界限的高手看看,谢谢!
李志林HZ 2002-11-11 11:24:30 ///////源代码开始
uses
Math;
function StrLeft(const mStr: string; mDelimiter: string): string;
begin
Result := Copy(mStr, 1, Pos(mDelimiter, mStr) - 1);
end; { StrLeft }
function ListValue(mList: string; mIndex: Integer; mDelimiter: string = ','): string;
var
I, L, K: Integer;
begin
L := Length(mList);
I := Pos(mDelimiter, mList);
K := 0;
Result := '';
while (I > 0) and (K <> mIndex) do begin
mList := Copy(mList, I + Length(mDelimiter), L);
I := Pos(mDelimiter, mList);
Inc(K);
end;
if K = mIndex then Result := StrLeft(mList + mDelimiter, mDelimiter);
end; { ListValue }
function StringGridToText(mStringGrid: TStringGrid;
mStrings: TStrings): Boolean;
var
I, J: Integer;
T: string;
begin
Result := False;
if (not Assigned(mStringGrid)) or (not Assigned(mStrings)) then Exit;
with mStringGrid do try
mStrings.Clear;
for J := 0 to RowCount - 1 do begin
T := '';
for I := 0 to ColCount - 1 do
T := T + #9 + Cells[I, J];
Delete(T, 1, 1);
mStrings.Add(T);
end;
except
Exit;
end;
Result := True;
end; { StringGridToText }
function TextToStringGrid(mStrings: TStrings;
mStringGrid: TStringGrid): Boolean;
var
I, J: Integer;
T: string;
begin
Result := False;
if (not Assigned(mStringGrid)) or (not Assigned(mStrings)) then Exit;
with mStrings, mStringGrid do try
for I := 0 to ColCount - 1 do begin
T := '';
for J := 0 to Min(RowCount - 1, Count - 1) do
Cells[I, J] := ListValue(Strings[J], I, #9);
end;
except
Exit;
end;
Result := True;
end; { TextToStringGrid }
///////源代码结束
///////使用示例开始
procedure TForm1.Button1Click(Sender: TObject);
begin
StringGridToText(StringGrid1, Memo1.Lines);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
TextToStringGrid(Memo1.Lines, StringGrid1);
end;
///////使用示例结束
菜鸟我试了一下,没成功,请各位帮个忙,谢谢!