Solved

SET SIZE OF THE FORM ON MY PROGRAM BY USING TTRAYICON. HOW CAN I.

Posted on 2006-06-29
10
222 Views
Last Modified: 2010-04-05
HOW CAN I SET SIZE OF ANY FORM IN MY APPLICATION USING MY COMPONENT TTRAYICON.

MAKE SET WHEN CREATE FORM.

WHEN CLOSE FORM SAVE SIZE, NAME.

QUESTIONS:

HOW IS GOING TO BE THE FUNCTION TO SAVE AND SET THIS CONFIGURATION ON INI FILE.
0
Comment
Question by:rafaelrgl
  • 5
  • 5
10 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17015191
uses inifiles;

To load a form's position from an ini file :-
begin
    with TINIFile.create('form positions.ini') do
    try
        Form1.SetBounds(
                                    ReadInteger('Form1', 'Top', Form1.Top),
                                    ReadInteger('Form1', 'Left', Form1.Top),
                                    ReadInteger('Form1', 'Width', Form1.Top),
                                    ReadInteger('Form1', 'Height', Form1.Top)
                                  );
    finally
        free;
    end;
end;

And when you want to save the form's position :-
begin
    with TINIFile.create('form positions.ini') do
    try
        WriteInteger('Form1', 'Top', Form1.Top);
        WriteInteger('Form1', 'Left', Form1.Top);
        WriteInteger('Form1', 'Width', Form1.Top);
        WriteInteger('Form1', 'Height', Form1.Top);
    finally
        free;
    end;
end;
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17015199
oops, should be...

To load a form's position from an ini file :-
begin
    with TINIFile.create('form positions.ini') do
    try
        Form1.SetBounds(
                                    ReadInteger('Form1', 'Top', Form1.Top),
                                    ReadInteger('Form1', 'Left', Form1.Left),
                                    ReadInteger('Form1', 'Width', Form1.Width),
                                    ReadInteger('Form1', 'Height', Form1.Height)
                                  );
    finally
        free;
    end;
end;

And when you want to save the form's position :-
begin
    with TINIFile.create('form positions.ini') do
    try
        WriteInteger('Form1', 'Top', Form1.Top);
        WriteInteger('Form1', 'Left', Form1.Left);
        WriteInteger('Form1', 'Width', Form1.Width);
        WriteInteger('Form1', 'Height', Form1.Height);
    finally
        free;
    end;
end;
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17020504
I would like to get the name and position when the form is created using some code in my component ttrayicon, i don't want put the name of the form by myself, like that:

WriteInteger('Form1', 'Top', Form1.Top);
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:rafaelrgl
ID: 17020521
This code is going to be inside my component ttrayicon, I think that's a big problem.
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 17027973
easy, all you do is have a property in your trayicon

e.g

private
    fFormToSaveSettingsFor: TForm;
published
    property FormToSaveSettingsFor: TForm read fFormToSaveSettingsFor write fFormToSaveSettingsFor;
end;

the user sets
MyTrayIcon.FormToSaveSettingsFor := Form1;

and then you just go
if assigned(fFormToSaveSettingsFor) then
  //Save Settings
// use FormToSaveSettingsFor.TOp, FormToSaveSettingsFor.Left, etc...
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17027974
FormToSaveSettingsFor.Caption or FormToSaveSettingsFor.Name to get the caption or name respectively
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17034194
I'll give you the points, but like i sad, i don't want the user set the form, but my component ttrayicon save the position of all forms in the application whithout any code insert by user. Only thing the user is going to do is set a property on component to do that like this below:



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
THIS SET TRUE OR FALSE ON COMPONENT TO SAVE THE POSITION AND SIZE OF ANY FORM IN THE APPLICATION
BUT, HOW IS GOING TO SAVE THAT?
//////////////////////////////
private
    fActivePosition : Boolean;

protect
    procedure SetActivePosition(Value : Boolean); virtual;

published
    property ActivePosition : boolean read fActivePosition write SetActivePosition;


procedure TNucleo_TrayIcon.SetActivePosition(Value : Boolean);
begin
  //if (value <> fActivePosition) and not (csDesigning in ComponentState) then
  if value <> fActivePosition then
  Begin
      fActivePosition := Value;
  end;
end;
////////////////////////////////////////////////////////////////

///// can you help me to understand how this is going to work.
////  THANKS A LOT        
 
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17034516
oh I see now. use the Screen.Forms property then

var
  i : integer;
begin
  for  i := 0 to Screen.FormCount-1 do
  begin
// Screen.Forms[] returns a "TForm", so you can do anything you like with it eg.
      memo1.lines.add(Screen.Forms[i].Name);
  end;
end;
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17034620
HOW CAN I KNOW WHEN THE FORM IS CREATING?
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17034621
OR THE FORM IS CLOSING?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Firemonkey Need Sample for Online Shopping Example. 2 168
URL for downloading Google Chrome for Win XP 2 191
Delphi 2 69
Twebbrowser add css to the header 3 29
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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