برنامه نویس

به وبلاگ خودتان خوش آمدید.

برنامه نویس

به وبلاگ خودتان خوش آمدید.

هندل کردن خطاهای رخ داده شده در برنامه دلفی

هندل کردن خطاهای رخ داده شده در برنامه دلفی در زمان try except


{
In addition to displaying the exception message, which 
happens by default, the following code shuts down the 
application when an exception is not caught and handled.  
AppException should be declared a method of TForm1.
}
procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := AppException;
end;

procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
  Application.ShowException(E);
  Application.Terminate;
end; 

procedure TForm1.Button1Click(Sender: TObject);
begin
  raise EPasswordInvalid.Create('Incorrect password entered');
end;

به دست آوردن نام فرم ها در دلفی

برای به دست آوردن نام فرم ها در دلفی از کد زیر می توان استفاده کرد



procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
begin
for I:= 0 to Screen.CustomFormCount - 1 do
    Memo1.Lines.Add(Screen.Forms[I].Caption);
end;


و برای نمایش ابجکتهای هر فرم از کد زیر :


var
i:integer;
begin
with Application do
for i:=0 to componentcount-1 do
    if components[i] is TForm then showmessage(components[i].Name);
end;