Hello again,
Well I thought I had this figured out, but it seems not...
My program has a form which when opened reads in 'n' 'reasons'
(strings) and displays each in it's own TLabel which the user
can edit.
I wasn't originally going to use TLabels as I figured a
TStringGrid would be the most suitable, but you can't have
multi-line entries in a string grid, and I thought of using
TMemo boxes which are easily editable, but which it is hard to
get to resize to fit the text - while each string isn't going to
have carriage returns, I want the strings to word wrap to fit on
multiple lines if need be without scrollbars (except on the form
itself if needed). Each reason is seperated from the last by a
bevel line which I put in a TList too....
Anyway the problem is that it all seems to be read in fine, it's
just not displaying anything - here is (hopefully) the relevant
code:
unit reasons;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, stdctrls, extctrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
theReasons:TList;
theSeperators:TList;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
theReasons:=TList.create;
theSeperators:=TList.create;
end;
procedure TForm1.FormShow(Sender: TObject);
var
i:integer;
tmpReason:TLabel;
tmpSeperator:TBevel;
begin
tmpSeperator:=TBevel.Create(Form1);
tmpReason:=TLabel.Create(Form1);
tmpSeperator.parent:=(Form1);
tmpReason.parent:=(Form1);
tmpSeperator.visible:=true;
tmpReason.visible:=true;
tmpReason.Caption:='Moo!';
theSeperators.add(tmpSeperator);
theReasons.add(tmpReason);
showmessage('tmpReason = '+tmpReason.caption+' and list = '
+TLabel(theReasons.Items[0]).caption);
end;
end.
This form is created and destroyed from the main form with the
following code:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs,
StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses reasons;
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
begin
with TForm1.create(Application) do
try
ShowModal;
finally
free;
end;
end;
end.
Ok the above form2 is the main form (the second one) and form1
is not automatically created in the project, but created when
the button is pressed.
The showmessage when the form is created does display:
tmpreason = Moo! and list = Moo!
so why aren't they displaying???? I've set their visable
properties to true, and put them in places where they will
definately be seen...
OK, I've tested it a bit more and found out something... If I
run form1 on it's own, it works fine, it's when form1 is not
created at startup but created when the button is pressed that
it doesn't work. Can anyone tell me what I need to do to work
around this? (ooh - I *did* have the code right, it just
doesn't work in this situation...)
Regards
OgO
--
Unless otherwise specified, all my posts relate to Delphi 3.
My Freeware: http://qjc.cjb.net/freeware.html
My Win9x Cursors: http://qjc.cjb.net/cursors.html
Feel free to ICQ me. My ICQ #: 12889482
I left my Glasses in my email - you better take them out!