>>How can I grab the parameters specified in the Run|Parameters menu
option
>>during development. I know I can get them during runtime but
I have a
>>component that needs to grab the parameters when it is dropped on
to the
>>form. It can grab the parameters when the component is created
dynamically
>>but I would like to have them when the developer drops the component
onto
>>the form.
These parameters are stored in the project's *.dof file, under the
[Parameters] section. You may want to read the stuff from there, but
they
are only updated if project file is saved, not each time user changes
them
from IDE.
---
Cool! What a clever solution!
The .DOF file has the internal format of an .INI file, so a TIniFile
object makes getting this value simple.
I should point out that the file used for the same purposes in Delphi
1
had an .OPT extension instead.
Here's the code for a simple form that demonstrates how this can work:
-------------------->8 cut here 8<--------------------
unit ParamU;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, IniFiles,
type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{Private declarations }
public
{Public declarations }
DOFFile : TIniFile ;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
DOFName : string ;
begin
{$ifdef Win32 }
DOFName := ChangeFileExt( Application.ExeName, '.DOF' ) ;
{$else }
DOFName := ChangeFileExt( Application.ExeName, '.OPT' ) ;
{$endif }
DOFFile := TIniFile.Create( DOFName ) ;
Edit1.Text := DOFFile.ReadString( 'Parameters', 'RunParams',
'' ) ;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DOFFile.Free ;
end;
end.
-------------------->8 cut here 8<--------------------
Now, in order to access this same info at design time, you may need
to
query the IDE using ToolServices or something. The main thing
probably
being the path to the project.
----------