Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Setting Form1.BorderIcons in code

Posted on 2003-10-30
9
992 Views
Last Modified: 2007-12-19
I prefer to set properties in code rather than via the object inpsector as I find it more maintainable that way.

I want to set

  Form1.BorderIcons := [];
  Form1.Position       := poMainFormCenter;

in code. It gived a visiblity erro if I try and set them in my Form1.FormCreate, If I try in Form1.FormShow the assigments are not effective whereas they are if Is et them in the object inspector. How can I achieve this in code?

Thanks, Tom.
0
Comment
Question by:tomcorcoran
  • 4
  • 3
  • 2
9 Comments
 
LVL 2

Assisted Solution

by:j42
j42 earned 50 total points
ID: 9651467
Hi,

I nearly always reintroduce the constructor of my forms. Thus you can't create them like
  myForm := Application.CreateForm(TMyForm, myForm);
Use
  myForm := TMyForm.Create(new parameter list);
instead.

type
  TMyForm = class(TForm)
  public
    contructor Create; reintroduce;
    ...
  end;

constructor TMyForm.Create;
begin
  inherited Create(Nil);  // Nil: no owner
  Self.BorderIcons := [];
  Self.Position := poWhatever;
end;

Don't forget to remove the Application.CreateForm(...) from your *.dpr file!

Cheers
0
 

Author Comment

by:tomcorcoran
ID: 9675501
Thanks for the post.

I did not have much luck with your method. I create all my forms ont he fly so did not have to change any CreateForms. I removed the FomrCreate event and tried adding :

   constructor Create; reintroduce;
 ..

constructor TMyForm1.Create;
begin
  inherited Create(Nil);  // Nil: no owner
 
  MyCombo.Style  := csDropDownList;
end;

This does not work. I have to set the style in the object inspector for the items dropdown to show.

Thanks, Tom.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9677253
works like a charme

procedure TForm1.FormCreate(Sender: TObject);
begin
  BorderIcons := [];  //just left out Form1
  Position       := poMainFormCenter;
  combobox1.Style := csDropDownList;
end;

?? didn't understand the question -> problem

meikl ;-)
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:tomcorcoran
ID: 9677452
So they all show for you? What if you do a combobox1.items.commatext := 'one,two,three'; Does that show too?

I wonder why they don't show for me unless thay are in the object inpector. From j42's comment above he would appear to know what I am talking about and has experienced the problem.

Confused now.

Cheers, Tom.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 9677468
?? no prob

procedure TForm1.FormCreate(Sender: TObject);
begin
  BorderIcons := [];
  Position       := poMainFormCenter;
  combobox1.Style := csDropDownList;
  combobox1.items.commatext := 'one,two,three';
end;

meikl ;-)
0
 
LVL 2

Expert Comment

by:j42
ID: 9679944
> From j42's comment above he would appear to know what I am talking about and has experienced the problem.
Yep, I had similar problems but I can't remember exactly. The only thing I know is that sometimes the OnCreate event is
'too late', thus the hiding of the original constructor. And I can remember other members of EE asking qusetions about
the same topic.
I played a little with the BorderIcons property and it seams that you can use it in the OnCreate event. I don't know what's
wrong with your code. I tried SDI and MDI apps, Application.CreateForm and Form1 := TForm1.Create(Nil). Everything worked
ok...
Just another guess. Try to replace all the instances (Form1, Form2) by the Self keyword. If it works I will explain why. Sorry,
don't know what else to do.
0
 

Author Comment

by:tomcorcoran
ID: 9680392
thanks for the info. Not sure what you mean by "Try to replace all the instances (Form1, Form2) by the Self keyword". I create all froms on the fly, normally they are embeded in other forms so the create goes like
  TheForm := Self.Create(ParentPanel.Owner);
with TheForm reference being local only to a procedure and killed at the end.

Thanks for the testing. I'll have to figure out why mine does not get called.

Cheers, Tom.
0
 
LVL 2

Expert Comment

by:j42
ID: 9681947
Ok, maybe you are aware of all that stuff. If so, please kindly skip this comment ;-)

let's say you have a class TYourForm and a global variable YourForm in YourFormUnit.pas.
In your *.dpr file there is something like Appliaction.CreateForm(TYourForm, YourForm). In
your procedure you have a local variable theForm: TYourForm and you call
theForm := TYourForm.Create(ParentPanel.Owner). Your OnCreate handler looks something
like this:

procedure TYourForm.CreateForm(Sender...);
begin
  YourForm.BorderIcons := [];
end;
=> Error.

YourForm is not a dangling reference since the CreateForm in the *.dpr file but you don't
want to change any property of YourForm but of theForm (the local one).

procedure TYourForm.CreateForm(Sender...);
begin
  theForm.BorderIcons := [];
end;
will work but it's bad style.

procedure TYourForm.CreateForm(Sender...);
begin
  Self.BorderIcons := [];
end;
is what I prefer.

Hope this was clear enough.
0
 

Author Comment

by:tomcorcoran
ID: 9949708
This wasn't working and then started working again...one of those weird delphi problems.  I am trying to think of an example of why you would reinstroduce the form create.

chees, tom.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
drawing animated level bar based on numbers 3 103
Base1 Encode/Decode 3 81
Drag & Drop... Data from one grid to another 2 40
Multi-layered image in FireMonkey 9 48
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question