본문 바로가기
Delphi Tip/컴포넌트

TList 활용하기

by MonoSoft 2021. 10. 29.
728x90
반응형

TList활용하기

 

 

unit Unit1;

 

interface

 

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

 

type

TMyData=record

SAW_CODE:String;

FName:String;

end;

 

MyData=^TMyData;

 

type

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

procedure Button1Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure FormClose(Sender: TObject; var Action: TCloseAction);

procedure Button2Click(Sender: TObject);

 

private

{ Private declarations }

public

{ Public declarations }

end;

 

var

Form1: TForm1;

MyList:TList;

implementation

 

uses Unit2;

 

{$R *.dfm}

 

procedure TForm1.Button1Click(Sender: TObject);

var PMyData:MyData;

begin

Form2:=TForm2.Create(Application);

New(PMyData);

PMyData^.SAW_CODE:='최광배';

PMyData^.FName:=Form2.Name;

MyList.Add(Pointer(PMyData));

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

MyList:=TList.Create;

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin

MyList.Free;

MyList:=nil;

end;

 

procedure TForm1.Button2Click(Sender: TObject);

var i:Integer;

begin

For i:=MyList.Count-1 downto 0 do begin

if Application.FindComponent(MyData(MyList.Items[i])^.FName)=nil then

MyList.Delete(i);

end;

For i:=0 to MyList.Count-1 do begin

TForm(Application.FindComponent(MyData(MyList.Items[i])^.FName)).Caption:=MyData(MyList.Items[i])^.FName;

TForm(Application.FindComponent(MyData(MyList.Items[i])^.FName)).Show;

end;

end;

 

end.

 

 

 

728x90
반응형

댓글