Delphi Öн«¶ÔÏó×÷Ϊ²ÎÊý´«µÝµÄʹÓà ¾ÙÀý·ÖÎö
2009-07-24 13:40
ÏÂÃæµÄµ¥»÷ʼþ£¬½«Òªµ÷ÓÃÒ»¸öÒÔ¶ÔÏóΪ²ÎÊýµÄ·½·¨£¬²¢½«½á¹ûÏÔʾ³öÀ´¡£
procedure TForm1.btn1Click(Sender: TObject);
var
lStrings: TStrings;
begin
lStrings:= TStringList.Create;
try
lStrings.Add('chen');
GetOperatorAllDeptIDs(lStrings);
ShowMessage(lStrings.Text);
finally
lStrings.Free;
end;
µ÷Ó÷½·¨Ò»£º
function GetOperatorAllDeptIDs( AStrings: TStrings):String;
begin
//×¢ÊÍ AStrings:= TStringList.Create;
AStrings. Add('zhi');
end;
·µ»Ø½á¹ûΪ£ºchen zhi
·ÖÎö£º´Ëʱ´«µÝµÄAStrings ΪlStrings¶ÔÏóµÄ¶ÔÏóÒýÓø±±¾£¬¼´Ò²Ö¸Ïò¶ÔÏólStrings£¬ËùÒÔµ±Ö´ÐÐAStrings. Add('zhi');ʱ²Ù×÷ΪlStrings¶ÔÏóÌí¼Ó‘zhi’¡£
µ÷Ó÷½·¨¶þ£º
function GetOperatorAllDeptIDs( var AStrings: TStrings):String;
begin
//×¢ÊÍ AStrings:= TStringList.Create;
AStrings. Add('zhi');
end;
·µ»Ø½á¹ûΪ£ºchen zhi
·ÖÎö£º´Ëʱ´«µÝµÄAStrings ΪlStrings¶ ......
(Ò») ʹÓö¯Ì¬´´½¨µÄ·½·¨
Ê×ÏÈ´´½¨ Excel ¶ÔÏó£¬Ê¹ÓÃComObj:
var ExcelApp: Variant;
ExcelApp := CreateOleObject( 'Excel.Application' );
1) ÏÔʾµ±Ç°´°¿Ú£º
ExcelApp.Visible := True;
2) ¸ü¸Ä Excel ±êÌâÀ¸£º
ExcelApp.Caption := 'Ó¦ÓóÌÐòµ÷Óà Microsoft Excel';
3) Ìí¼Óй¤×÷²¾£º
ExcelApp.WorkBooks.Add;
4) ´ò¿ªÒÑ´æÔڵŤ×÷²¾£º
ExcelApp.WorkBooks.Open( 'C:\Excel\Demo.xls' );
5) ÉèÖõÚ2¸ö¹¤×÷±íΪ»î¶¯
¹¤×÷±í£º
ExcelApp.WorkSheets[2].Activate;
»ò
ExcelApp.WorksSheets[ 'Sheet2' ].Activate;
6) ¸øµ¥Ôª¸ñ¸³Öµ£º
ExcelApp.Cells[1,4].Value := 'µÚÒ»ÐеÚËÄÁÐ';
7) ÉèÖÃÖ¸¶¨ÁеĿí¶È£¨µ¥Î»£º×Ö·û¸öÊý£©£¬ÒÔµÚÒ»ÁÐΪÀý£º
ExcelApp.ActiveSheet.Columns[1].ColumnsWidth := 5;
8) ÉèÖÃÖ¸¶¨Ðеĸ߶ȣ¨µ¥Î»£º°õ£©£¨1°õ£½0.035ÀåÃ×£©£¬ÒÔµÚ¶þÐÐΪÀý£º
ExcelApp.ActiveSheet.Rows[2].RowHeight := 1/0.035; // 1ÀåÃ×
9) ÔÚµÚ8ÐÐ֮ǰ²åÈë·ÖÒ³·û£º
ExcelApp.WorkSheets[1].Rows[8].PageBreak := 1;
10) ÔÚµÚ8ÁÐ֮ǰɾ³ý·ÖÒ³·û£º
ExcelApp.ActiveSheet.Columns[4].PageBreak := 0;
11) Ö¸¶¨±ß¿òÏß¿í¶È£º
ExcelApp.ActiveSheet.Range[ ......
delphi TStringList Ó÷¨Ïê½â
//TStringList ³£Ó÷½·¨ÓëÊôÐÔ
:
var
List: TStringList;
i: Integer;
begin
List := TStringList.Create;
List.Add('Strings1'); {Ìí¼Ó}
List.Add('Strings2');
List.Exchange(0,1); {Öû»}
List.Insert(0,'Strings3'); {²åÈë}
i := List.IndexOf('Strings1'); {µÚÒ»´Î³öÏÖµÄλÖÃ}
List.Sort; {ÅÅÐò}
List.Sorted := True; {Ö¸¶¨ÅÅÐò}
List.Count; {×ÜÊý}
List.Text; &n ......
Êý×éÊÇ¿ÉÒÔͨ¹ýË÷ÒýÀ´ÒýÓõÄͬÀàÐÍÊý¾ÝµÄÁÐ±í¡£°´ÕÕ´æ´¢¿Õ¼äµÄ»ñÈ¡·½Ê½£¬Delphi
Ö§³ÖµÄÊý×éÀàÐÍÓÐÁ½ÖÖ£¬¼´¾²Ì¬Êý×éºÍ¶¯Ì¬Êý×é¡£Ëùν¾²Ì¬Êý×é¾ÍÊÇÔÚÉùÃ÷ʱ¾ÍÒѾȷ¶¨´óСµÄÊý×éÀàÐÍ£¬¶ø¶¯Ì¬Êý×éÊÇÖ¸Æä´óСÔÚÉùÃ÷ʱ²»ÄÜÈ·¶¨µÄÊý×飬¶¯Ì¬Êý×éµÄ´óСÔÚʹÓÃʱȷ¶¨¡£
ÉùÃ÷¾²Ì¬Êý×éµÄ·½Ê½·Ç³£¼òµ¥£¬Ö»ÒªÖ¸Ã÷Êý×鳤¶ÈºÍÊý¾ÝÀàÐͼ´¿É£¬ÏÂÃæ¾ÍÊÇÉùÃ÷ÁËÒ»¸öÓÃÀ´´æ·Å×Ö·ûµÄÊý×飺
var Hello: array[0..5] of
char;
ÈÝÒ׿´³ö£¬Êý×éµÄÉùÃ÷Ã÷ÏÔ°üº¬3
¸ö²¿·Ö£¬¹Ø¼ü´Êarray
±íÃ÷ÕâÊÇÒ»¸öÊý×é±äÁ¿£¬¶ø[x..y]
±íÃ÷Êý×éµÄË÷ÒýÊÇ´Óx
µ½y
£¬¶øof
char
±íÃ÷Êý×éµÄ³ÉÔ±ÊÇ×Ö·ûÀàÐÍ¡£°´ÕÕÀàËƵķ½·¨»¹¿ÉÒÔÉùÃ÷ÆäËûÀàÐ͵ÄÊý×飬ÏÂÃæ¾ÍÊÇÕâÑùµÄʾÀý´úÂ룺
var ScoreList: array[1..25] of
Integer;
var NameList: array[1..35] of
String;
ÉùÃ÷ÁËÊý×éºó£¬¿ÉÒÔͨ¹ýË÷ÒýÒýÓÃÊý×éµÄÔªËØ(
³ÉÔ±)
¡£¶øʹÓÃÊý×é³ÉÔ±µÄ·½·¨ÓëʹÓÃÕâÖÖÀàÐ͵ÄÆÕͨ±äÁ¿ÀàËÆ£¬ÏÂÃæ¾ÍÊÇÒ»¶ÎʹÓÃ×Ö·ûÊý×éµÄʾÀý´úÂ룺
var Hello: array[0..5] of
char;
begin
Hello[0] := ‘H’;
Hello[1] := ‘e’;
Hello[2] := ‘l’;
Hello[3] := ‘l’ ......
1¡¢ ·ÅÒ»ÏÂmemo¿Ø¼þ¡¢Ò»¸öbutton¡¢opendialog
ÔÚbuttonµÄclickʼþÖÐ
if opendialog1.Execute then
memo1.Lines.LoadfromFile(opendialog1.filename);
2¡¢Àļòµ¥µÄÊ°¡
var
Mytxt : TStringList;
begin
MyText :=
TStringList('ÄãµÄÎı¾Îļþ¼°Â·¾¶');
MyText.Free;//ʹÍêºóÒªFREEŶ
end;
ÓÃÒ»¸öMemo£¬È»ºóÓÃMemo1.Lines.LoadfromFile('C:\...\*.txt');
OK!
»¹ÓÐÒ»ÖÖ·½·¨£º
var
f:textfile;
s:string;
begin
assignfile(f,'·¾¶ºÍÎļþÃû.txt');
reset(f);
readln(f,s);
showmessage(s);
closefile(f);
end; ......
֮ǰ×öÒ»¸ö³ÌÐò£¬ÓÃListBox¶ÁÈëÒ»¸öÎı¾Îļþ£¬µ«Îı¾ÖÐÓпÕÐУ¬ÎªÁËɾ³ýÆäÖеĿÕÐУ¬ÕÛÌÚÁ˺ó¤Ê±¼ä¡£
Ïȸø³öÒ»¶Î´úÂë¸ø´ó¼Ò¿´
var
i:Integer;
begin
ListBox1.Items.LoadfromFile('data.txt');
for i:=0 to ListBox1.Count - 1 do
begin
if Trim(ListBox1.Items.Strings[i])='' Then
ListBox1.Items.Delete(i);
end;
end;
ÏàÐŲ»ÉÙÈË»áÕâÑùд£¨°üÀ¨ÎÒÒÔÇ°Ò²ÊÇ£©£¬ÌرðÊÇÐÂÊÖ£¬µ«ÊÇÕâÊÇÐв»Í¨µÄ£¬ÔËÐÐʱ¸ø³ö list index out of bounds ´íÎó£¨Ï±곬½ç£©£¬ÎªÊ²Ã´»áÕâÑùÄØ£¿
Ö÷ÒªÊÇÕâ¸öforÑ»·ÖÐtoºóÃæµÄ ListBox1.Count ÒÑÊÇ×÷Ϊһ¸ö¹Ì¶¨Öµ£¬²»»á¸Ä±äµÄ£¬¶øÏÂÃæÖ´ÐÐÁËListBox1.Items.Delete(i); £¬µ¼ÖÂListBox1 ÖеÄÊýÄ¿¼õÉÙ£¬ËùÒÔ»á³öÏÖϱ곬½çµÄ´íÎó¡£
Æäʵ½â¾öÕâ¸öÎÊÌâºÜ¼òµ¥£¬¸Ä±äÒ»ÏÂ˼ά·½Ê½¾Í¿ÉÒÔÁË£¬½«forÑ»·¸ÄΪ
i:=ListBox1.Count - 1;
while(i>0)do
begin
if Trim(ListBox1.Items.Strings[i])='' Then
ListBox1.Items.Delete(i);
Dec(i);
end;
ÑÝ ......