Creating Controls on a Page

InstallationWay

Новичок
Hi! Here is a method which will create static Text on a page:
Код:
procedure RedesignWizardForm;
begin
  staUninstall: = TNewStaticText.Create (WizardForm);
  with staUninstall do
  begin
    Parent: = WizardForm;
    AutoSize: = False;
    Caption: = '';
    Name: = 'Uninstall';
    Transparent: = True;
    TabStop: = True;
    Left: = ScaleX (08);
    Top: = ScaleY (321);
    Width: = ScaleX (81);
    Height: = ScaleY (25);
    Cursor: = crHand;
    TabOrder: = 1;
  end;

  staUninstall.OnClick: = @TextOnClick;
  staUninstall.OnMouseDown: = @TextMouseDown;
  staUninstall.OnMouseEnter: = @TextMouseEnter;
  staUninstall.OnMouseLeave: = @TextMouseLeave;
end;
It is working well. but ...
I have created a method doing this like this:
Код:
procedure CreateStaticText (staticText: TNewStaticText; name: String; left: Integer; top: Integer; width: Integer; height: Integer; tabOrder: Integer);
begin
  staticText: = TNewStaticText.Create (WizardForm);
  with staticText do
  begin
    Parent: = WizardForm;
    AutoSize: = False;
    Caption: = '';
    Name: = name;
    Transparent: = True;
    TabStop: = True;
    Left: = ScaleX (left);
    Top: = ScaleY (top);
    Width: = ScaleX (width);
    Height: = ScaleY (height);
    Cursor: = crHand;
    TabOrder: = tabOrder;
  end;

  staticText.OnClick: = @TextOnClick;
  staticText.OnMouseDown: = @TextMouseDown;
  staticText.OnMouseEnter: = @TextMouseEnter;
  staticText.OnMouseLeave: = @TextMouseLeave;
end;
and then edit the first method like this:
Код:
 procedure RedesignWizardForm;
begin
  CreateStaticText (staUninstall, 'Uninstall', 8, 321, 81, 25, 1);
end;
but it will not work :( why?
 
Последнее редактирование модератором:

Nemko

Дилетант
Модератор
Eng: InstallationWay, try using a function, not a procedure like in the example below:
Rus: InstallationWay, попробуйте использовать функцию, а не процедуру, как в примере ниже:
Код:
[Setup]
AppName=My Application
AppVersion=1.5
CreateAppDir=no

[*Code]
//--(Module)
function CreateStaticText(MyName: String; X, Y, W, H, TAB: Integer): TNewStaticText;
begin
  Result:=TNewStaticText.Create(nil);
  with Result do begin
    AutoSize:=False;
    Caption:='';
    Cursor:=crHand;
    Name:=MyName;
    Transparent:=True;
    TabOrder:=TAB;
    TabStop:=True;
    Setbounds(ScaleX(X), ScaleY(Y), ScaleX(W), ScaleY(H));
    Parent:=WizardForm;
  end;
end;

procedure stSetEvent(st: TNewStaticText; stClick, stMouseEnter, stMouseLeave: TNotifyEvent; stMouseDown: TMouseEvent);
begin
  with st do begin
    if stClick <> nil then OnClick:=stClick;
    if stMouseEnter <> nil then OnMouseEnter:=stMouseEnter;
    if stMouseLeave <> nil then OnMouseLeave:=stMouseLeave;
    if stMouseDown <> nil then OnMouseDown:= stMouseDown;
  end;
end;

//--(Code)
var
  MyText: TNewStaticText;

procedure MyClick(Obj: TObject);
begin
  WizardForm.Caption:='Click';
end;

procedure MyEnter(Obj: TObject);
begin
  WizardForm.Caption:='Enter';
end;

procedure MyLeave(Obj: TObject);
begin
  WizardForm.Caption:='Leave';
end;

procedure MyMouseDown(Obj: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  WizardForm.Caption:='Mouse Down';
end;

procedure InitializeWizard;
begin
  WizardForm.OuterNotebook.Hide;
  MyText:=CreateStaticText('Test', 10, 10, 100, 25, 1);
  stSetEvent(MyText, @MyClick, @MyEnter, @MyLeave, nil);
end;
 
Сверху