Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not getting the correct values for the Top and Left properties of a fo

Status
Not open for further replies.

CarrahaG

Programmer
Mar 25, 2007
98
AW
Hello

We need to read the Top & Left coordinates of a Window and for some reason we are not getting the

correct values.


Please see the code below.


**************************************************************
unit Utilities;

procedure TfrmUtilities.FormShow(Sender: TObject);
begin
Main.frmMain.LoadWindowSettings('UtilitiesWindow', Self);

ShowMessage('Utilities Top -> ' + IntToStr(frmUtilities.Top));
ShowMessage('Utilities Left -> ' + IntToStr(frmUtilities.Left));

end;**************************************************************



**************************************************************
unit Main;

procedure TfrmMain.LoadWindowSettings(myWindow: string; myForm: TForm);
var
myIniFile : TIniFile;
myIniFileName : string;

begin
myIniFileName := ExtractFilePath(Application.ExeName) +
ChangeFileExt(ExtractFileName(Application.ExeName), '.ini');

myIniFile := TIniFile.Create(myIniFileName);
try
myForm.Top := myIniFile.ReadInteger(myWindow,'Top',-1);
myForm.Left := myIniFile.ReadInteger(myWindow,'Left',-1);
myForm.Height := myIniFile.ReadInteger(myWindow,'Height',-1);
myForm.Width := myIniFile.ReadInteger(myWindow,'Width',-1);
finally
myIniFile.Free;
end;
end;
**************************************************************

**************************************************************
EDS.ini

[UtilitiesWindow]
Top=462
Left=894
Height=406
Width=401
**************************************************************



Procedure TfrmUtilities.FormShow is calling procedure LoadWindowSettings in unit Main. The

LoadWindowSettings is reading the EDS.ini file for the dimension and coordinates of the frmUtilities

Window. This works fine.

Right after the LoadWindowSettings is called, we read and display the cordinates of the frmUtilities

window. We assume that it should be equal to the values of Top and left cordinates that was read from

the EDS.ini file. However, it is completely different. When we run the ShowMessage commands we get:


Utilities Top -> 66
Utilities Left -> 66

Why is this so?



Regards,
Georges
 
Procedure TfrmUtilities.FormShow is calling procedure LoadWindowSettings in unit Main. The

LoadWindowSettings is reading the EDS.ini file for the dimension and coordinates of the frmUtilities

Window. This works fine.
It might be working but is not returning anything to it's caller.

I'm not surprised that no one answered your post, there is so much wrong with your code, it would take alot of typing to explain. Basically, you can't return parameters unless the passed param is declared as a VAR. But TForm.Self cannot be passed as a var.

Your use of 2 forms also complicates the problem.

I've posted a correction to demonstrate. The following works as you expected:
Code:
procedure TfrmMain.FormShow(Sender: TObject);
begin
  LoadWindowSettings('UtilitiesWindow');
  ShowMessage('Utilities Top -> ' + IntToStr(Self.Top) + #13 +
              'Utilities Left -> ' + IntToStr(Self.Left));
end;

procedure TfrmMain.LoadWindowSettings(myWindow: string);
var
  myIniFile : TIniFile;
  myIniFileName : string;
begin
  myIniFileName := ExtractFilePath(Application.ExeName) +
    ChangeFileExt(ExtractFileName(Application.ExeName), '.ini');
  myIniFile:= TIniFile.Create(myIniFileName);
  try
    Self.Top:= myIniFile.ReadInteger(myWindow,'Top',-1);
    Self.Left:= myIniFile.ReadInteger(myWindow,'Left',-1);
    Self.Height:= myIniFile.ReadInteger(myWindow,'Height',-1);
    Self.Width:= myIniFile.ReadInteger(myWindow,'Width',-1);
  finally
    myIniFile.Free;
  end;
end;

end.


Roo
Delphi Rules!
 
Roo & Aaron

Thanks very much to both of you.

Regards,
Georges
 
You are welcome.

Regarding RXLib: I used it back when it was one of the kings of free component sets with source. "Most rxlib components have been merged into the Jedi Visual Components Library (JVCL) so it is probably a better idea to use the JVCL for new projects."

If you already have the JVCL (who doesn't?) you will find what Aaron suggestd there. Installing both can create much confusion that I would avoid.


Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top