請教一下SetLength的基本問題 |
|
riverlan
一般會員 發表:7 回覆:10 積分:5 註冊:2002-03-13 發送簡訊給我 |
由於我對SetLength上不明白其用意,故請教各位專家
有關SetLength的定義。 如果說我想從LMDListBox裡的資料,
然後用SetLength來作為陣列的話,
不知道該如何應用
下面試我有關SetLength的程式 procedure TTSPSolverForm.BitBtn2Click(Sender: TObject);
var i,j,k,l,m,x:Integer;
A:array of integer;
isexist:Boolean;
S:String;
begin
isexist:=False;
Counter.StartTimeCount;
SetLength(A,LMDListBox1.Items.Count);
for i:=1 to StrToInt(FlopEdit.Text) do
begin
if LMDListBox2.Items.Count=0 then
begin
Randomize;
for j:=0 to LMDListBox1.Items.Count-1 do
begin
isexist:=False;
x:=random(LMDListBox1.Items.Count) 1;
for k:=0 to LMDListBox1.Items.Count-1 do
begin
if x=A[k] then isexist:=TRUE;
end;
while isexist do
begin
isexist:=False;
x:=random(LMDListBox1.Items.Count) 1;
for l:=0 to LMDListBox1.Items.Count-1 do
begin
if x=A[l] then isexist:=TRUE;
end;
end;
A[j]:=x;
S:='';
for m:=0 to LMDListBox1.Items.Count-1 do
begin
S:=S ' -> ' 'N' IntToStr(A[m]);
end;
//ShowMessage(S);
end;
//ShowMessage(FloatToStr(GetLength(A)));
LMDListBox2.Items.Add(IntToStr(LMDListBox2.Items.Count 1) ';' NumberSpinEdit.Text ';'
FloatToStr(GetLength(A)) ';' S);
end
else
begin
end
end;
TimeEdit.Text:=Counter.ElapsedSecs;
end; 想請教大家一下,
LMDListBox理的資料如下所示: 1 2 3
2 3 4
3 4 5
4 6 7
5 8 9
6 10 11
7 12 13
8 14 15 謝謝。
|
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
引言: 由於我對SetLength上不明白其用意,故請教各位專家 有關SetLength的定義。 如果說我想從LMDListBox裡的資料, 然後用SetLength來作為陣列的話, 不知道該如何應用 下面試我有關SetLength的程式 procedure TTSPSolverForm.BitBtn2Click(Sender: TObject); var i,j,k,l,m,x:Integer; A:array of integer; isexist:Boolean; S:String; begin isexist:=False; Counter.StartTimeCount; SetLength(A,LMDListBox1.Items.Count); for i:=1 to StrToInt(FlopEdit.Text) do begin if LMDListBox2.Items.Count=0 then begin Randomize; for j:=0 to LMDListBox1.Items.Count-1 do begin isexist:=False; x:=random(LMDListBox1.Items.Count) 1; for k:=0 to LMDListBox1.Items.Count-1 do begin if x=A[k] then isexist:=TRUE; end; while isexist do begin isexist:=False; x:=random(LMDListBox1.Items.Count) 1; for l:=0 to LMDListBox1.Items.Count-1 do begin if x=A[l] then isexist:=TRUE; end; end; A[j]:=x; S:=''; for m:=0 to LMDListBox1.Items.Count-1 do begin S:=S ' -> ' 'N' IntToStr(A[m]); end; //ShowMessage(S); end; //ShowMessage(FloatToStr(GetLength(A))); LMDListBox2.Items.Add(IntToStr(LMDListBox2.Items.Count 1) ';' NumberSpinEdit.Text ';' FloatToStr(GetLength(A)) ';' S); end else begin end end; TimeEdit.Text:=Counter.ElapsedSecs; end; 想請教大家一下, LMDListBox理的資料如下所示: 1 2 3 2 3 4 3 4 5 4 6 7 5 8 9 6 10 11 7 12 13 8 14 15 謝謝。不太明白您的程式用途, 但有一個地方語法有問題? FloatToStr(GetLength(A)) ';' S); 要改為 IntToStr(High(A)) ';' S); try it ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~ |
riverlan
一般會員 發表:7 回覆:10 積分:5 註冊:2002-03-13 發送簡訊給我 |
|
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
|
riverlan
一般會員 發表:7 回覆:10 積分:5 註冊:2002-03-13 發送簡訊給我 |
|
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
引言: 應該一為陣列就可以了, 只是我新手,還無法用隨機選取1~8 且不能重複 意思是說: 我希望得到的結果為13578642或2456317這樣的組合 就是1~8不能重複 但卻是隨機排列。 謝謝。早說嗎! 寫給您就是了! 拉一個Form1拉兩個Memo1/2拉一個Button1 Memo1內放1..8(到n也可以) 雙點Button1放入下列程式 procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin memo2.lines.clear; randomize; while memo1.Lines.count>0 do begin i:=random(memo1.lines.count); memo2.lines.add(memo1.Lines[i]); memo1.Lines.Delete(i); end; end;我的比你短吧! 加油!新鮮人! ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~ |
riverlan
一般會員 發表:7 回覆:10 積分:5 註冊:2002-03-13 發送簡訊給我 |
|
riverlan
一般會員 發表:7 回覆:10 積分:5 註冊:2002-03-13 發送簡訊給我 |
|
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
引言: [Error] Unit1.pas(14): Unsatisfied forward or external declaration: 'TForm1.Memo1Change' Memo1 have error??? 是我在宣告有問題嗎??是您不小心按了,Memo1的OnChange事件,又沒定義好的關系! 我就送佛送上天,程式寫上傳了! 請至網友作品區下載! 加油! ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~ |
tcw
一般會員 發表:0 回覆:1 積分:0 註冊:2002-03-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |