有谁会把下面的VB源代码翻译成Delphi的源代码?
Private Sub Command2_Click()
Dim S As String, Length As Long, pos As Integer
S = String(1024, 0)
Length = GetProfileString("windows", vbNullString, "", S, Len(S))
S = Left(S, Length)
List1.Clear
While Len(S) > 0
pos = InStr(S, Chr(0))
List1.AddItem Left(S, pos - 1)
S = Mid(S, pos + 1)
Wend
End Sub
Private Sub Command3_Click()
Dim S As String, Length As Long, pos As Integer
S = String(1024, 0)
Length = GetProfileString(vbNullString, vbNullString, "", S, Len(S))
S = Left(S, Length)
List1.Clear
While Len(S) > 0
pos = InStr(S, Chr(0))
List1.AddItem Left(S, pos - 1)
S = Mid(S, pos + 1)
Wend
End Sub
问题点数:47、回复次数:5Top
1 楼liubingqian(海风)回复于 2001-07-27 17:40:25 得分 0
不难啊!看两天Delphi的书也能改写啊。
程序有点儿长,这47分我不要了Top
2 楼Linux2001(闭关开发中)回复于 2001-07-27 17:42:56 得分 0
我看了好久的书都不会改耶!Top
3 楼trainbox(rain)回复于 2001-07-27 18:01:20 得分 27
Private Sub Command2_Click()
procedure Command2_Click()
var
s: string;
length1: Integer;
pos1: Integer;
begin
//S = String(1024, 0)
SetLength(s,1024);
Length1 := GetProfileString("windows", '', "", S, Length(S))
//S = Left(S, Length)
s:=Copy(s,1,length1);
List1.Clear
//While Len(S) > 0
while length(s)>0 do
begin
//pos = InStr(S, Chr(0))
pos1:=Pos(s,chr(0));
//List1.AddItem left(S, pos1 - 1)
List1.AddItem copy(S,1, pos1 - 1);
//S = Mid(S, pos + 1)
s:=copy(s,pos+1,1);
end
End;
下面类似
Private Sub Command3_Click()
Dim S As String, Length As Long, pos As Integer
S = String(1024, 0)
Length = GetProfileString(vbNullString, vbNullString, "", S, Len(S))
S = Left(S, Length)
List1.Clear
While Len(S) > 0
pos = InStr(S, Chr(0))
List1.AddItem Left(S, pos - 1)
S = Mid(S, pos + 1)
Wend
End Sub
Top
4 楼Linux2001(闭关开发中)回复于 2001-07-29 18:30:05 得分 0
to:trainbox()
你翻译的东东在delphi下会出错,比如S:=copy(s,1,length1)就不行Top
5 楼xzm2000(傻B)回复于 2001-07-29 18:58:47 得分 20
编译可以通过,但是运行会出错,呵呵
procedure TForm1.Button2Click(Sender: TObject);
var
s: string;
Mylength: longint;
Mypos: integer;
begin
setlength(s, 255);
MyLength := GetProfileString('windows', nil, '', pchar(S), Length(S));
S := copy(S, 1, MyLength);
ListBox1.Clear;
While Length(S) > 0 do
begin
Mypos := pos(S, Chr(0));
Listbox1.items.add(copy(S, 1, Mypos - 1));
S := copy(S, Mypos + 1, length(s) - MyPos);
end
end;Top




