Recent

Author Topic: [Solved]Forms and Units; Form Classes  (Read 18293 times)

cov

  • Full Member
  • ***
  • Posts: 246
Re: Forms and Units; Form Classes
« Reply #30 on: April 04, 2013, 01:03:35 pm »
So I need to create an empty LFM file?

I thought this:

Quote
constructor TFormB.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  Left:=442;
  Height:=338;
  Top:=40;
  Width:=676;
  Caption:='Incorporate into Database';
  Font.Name:='MS Sans Serif';
  Button3:=TButton.Create(Self);
  with Button3 do
  begin
    Parent:=Self;
    Left:=320;
    Height:=25;
    Top:=269;
    Width:=75;
    Caption:='Okay';
    Default:=True;
    OnClick:=@OkayButtonClick;
    TabOrder:=0;
  end;
  ComboBox1:=TComboBox.Create(Self);
  with ComboBox1 do
  begin
    Parent:=Self;
    Left:=56;
    Height:=21;
    Top:=269;
    Width:=100;
    ItemHeight:=13;
    OnChange:=@ComboBox1Change;
    TabOrder:=1;
  end;
  Label1:=TLabel.Create(Self);
  with Label1 do
  begin
    Parent:=Self;
    Left:=16;
    Height:=14;
    Top:=269;
    Width:=28;
    Caption:='Block';
  end;
  Panel1:=TPanel.Create(Self);
  with Panel1 do
  begin
    Parent:=Self;
    Left:=16;
    Height:=232;
    Top:=24;
    Width:=648;
    TabOrder:=2;
  end;
  ListBox1:=TListBox.Create(Panel1);
  with ListBox1 do
  begin
    Parent:=Panel1;
    Left:=72;
    Height:=201;
    Top:=7;
    Width:=185;
    ItemHeight:=0;
    MultiSelect:=True;
    OnClick:=@ListBox1Click;
    ParentShowHint:=False;
    ScrollWidth:=181;
    ShowHint:=True;
    TabOrder:=0;
  end;
  Button4:=TButton.Create(Panel1);
  with Button4 do
  begin
    Parent:=Panel1;
    Left:=264;
    Height:=25;
    Top:=24;
    Width:=67;
    Caption:='Select All';
    OnClick:=@Button4Click;
    TabOrder:=1;
  end;
  Button1:=TButton.Create(Panel1);
  with Button1 do
  begin
    Parent:=Panel1;
    Left:=264;
    Height:=25;
    Top:=64;
    Width:=67;
    Caption:='>>';
    OnClick:=@Button1Click;
    TabOrder:=2;
  end;
  Button2:=TButton.Create(Panel1);
  with Button2 do
  begin
    Parent:=Panel1;
    Left:=264;
    Height:=25;
    Top:=104;
    Width:=67;
    Caption:='<<';
    Enabled:=False ;
    TabOrder:=3;
  end;
  Label2:=TLabel.Create(Panel1);
  with Label2 do
  begin
    Parent:=Panel1;
    Left:=8;
    Height:=14;
    Top:=8;
    Width:=48;
    Caption:='Attributes:'
  end;
  AttrGrid:= TStringGrid.Create(Panel1);
  with AttrGrid do
  begin
    Parent:=Panel1;
    Left:=360;
    Height:=200;
    Top:=8;
    Width:=256;
    Anchors:=[akTop, akLeft, akRight, akBottom];
    ColCount:=2;
    FixedRows:=0;
    TabOrder:=4;
  end;
  CheckBox1:= TCheckBox.Create(Panel1);
  with CheckBox1 do
  begin
    Parent:=Panel1;
    Left:=16;
    Height:=17;
    Top:=312;
    Width:=39;
    Caption:='Text';
    OnClick:=@CheckBox1Click;
    TabOrder:=3;
  end;
  SelectDirectoryDialog1:=TSelectDirectoryDialog.Create(Self);
end;

carries all the information needed?
« Last Edit: April 04, 2013, 01:06:06 pm by cov »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Forms and Units; Form Classes
« Reply #31 on: April 04, 2013, 01:22:25 pm »
In that case just use the following.
Code: [Select]
var
  VReq : boolean;
  vForm : TForm;
begin
  VReq := RequireDerivedFormResource;
  RequireDerivedFormResource := False;
  try
    vForm := TFormB.Create(application);
    try
      vform.showModal;
    finally
      VForm.Free;
    end;
  finally
    RequireDerivedFormResource := VReq;
  end;
end;
« Last Edit: April 04, 2013, 02:00:58 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

cov

  • Full Member
  • ***
  • Posts: 246
Re: Forms and Units; Form Classes
« Reply #32 on: April 04, 2013, 02:18:10 pm »
Thanks, that works.

 8)


cov

  • Full Member
  • ***
  • Posts: 246
Re: [Solved]Forms and Units; Form Classes
« Reply #33 on: April 06, 2013, 03:07:33 pm »
At what point can I start filling up the combobox on the form?

I have used vForm := TFormB.Create(application); as you suggested, but the when I subsequently try to add strings into the Combobox I get a SIGSEGV exception.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: [Almost Solved]Forms and Units; Form Classes
« Reply #34 on: April 06, 2013, 03:51:04 pm »
anywhere after the vForm := TFormB.Create(application); line its ok to use the components in the form just make sure that the vForm declaration is of type TFormB instead of TForm that I have set it and you access the combobox as vForm.ComboBox1.[.......].
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

cov

  • Full Member
  • ***
  • Posts: 246
Re: [Almost Solved]Forms and Units; Form Classes
« Reply #35 on: April 06, 2013, 04:32:29 pm »
Thanks.

It didn't work when I created the form from the first calling unit, but when I moved all the code across to the unit containing the Form's definition declarations it worked.

Many thanks.

Dave Coventry

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: [Solved]Forms and Units; Form Classes
« Reply #36 on: April 06, 2013, 08:53:04 pm »
I guess the combobox1 is not a public or publish variable it is protected or private in that case you should add a public method that adds items to the combobox and use that instead of using the variables directly at least that is what I am doing in my code anyway.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018