iniBrowser BETA (Updated 11.03.2012)
Posted: Sun Nov 07, 2010 9:22 am
Download iniBrowser BETA for DataCAD 15 (Updated 11.03.2012)
Download iniBrowser BETA for DataCAD 14 (Updated 11.03.2012)
Download iniBrowser BETA for DataCAD 13 (Updated 11.20.2010)
'iniBrowser' BETA is a DCAL for Delphi Macro. I developed this macro to learn how to incorporate Delphi forms into a DataCAD macro.
This macro allows you to browse and edit all of the keys in your DCADWIN.INI file located in the DataCAD program folder. The INI sections and keys are organized alphabetically.
Enjoy!
Here is the source code to the main unit 'iniBrowser.dpr':
Here is the source code to the main form unit 'iniBrowserForm.pas':
Download iniBrowser BETA for DataCAD 14 (Updated 11.03.2012)
Download iniBrowser BETA for DataCAD 13 (Updated 11.20.2010)
'iniBrowser' BETA is a DCAL for Delphi Macro. I developed this macro to learn how to incorporate Delphi forms into a DataCAD macro.
This macro allows you to browse and edit all of the keys in your DCADWIN.INI file located in the DataCAD program folder. The INI sections and keys are organized alphabetically.
Enjoy!
Here is the source code to the main unit 'iniBrowser.dpr':
Code: Select all
{
DCAL program iniBrowser.
}
library iniBrowser;
uses
// Delphi Units
Forms,
// iniBrowser Units
iniBrowserForm in 'iniBrowserForm.pas' {iniForm},
// DCAL for Delphi Units
UConstants in '..\..\Header Files\UConstants.pas',
UInterfaces in '..\..\Header Files\UInterfaces.pas',
UInterfacesRecords in '..\..\Header Files\UInterfacesRecords.pas',
URecords in '..\..\Header Files\URecords.pas',
UVariables in '..\..\Header Files\UVariables.pas';
{$E dmx} //dmx is the extension for DCAL Dll's
{$R *.res}
//The values stored in the records you define here will be rememberd
//between dispatcher calls because they are pushed onto the command stack
type
iniBrowserL = record
state: asint;
case byte of
0: (getp: getpointArg);
end;
PiniBrowserL = ^iniBrowserL;
//Main Function (Re-entrant State Machine)
function iniBrowser_main(act : action; pl, pargs : Pointer) : wantType;
//The values stored in variables you define here will not be retained
//between dispatcher calls because they are not pushed onto the stack
var
retval : asint;
l : PiniBrowserL;
begin
l := PiniBrowserL(pl);
{Section 3: Aagain - Return to menus and wait for input}
if act = aagain then begin { Re-entrant section }
case l.state of { Case }
1 :
begin
//If a key was pressed or a menu button was selected...
if l.getp.Result = res_escape then begin
case l.getp.key of
f1 : l.state := 2; {Show Form}
s0 : l.state := 0; {Exit}
end; { Which key was pressed }
end; { Was a key pressed or menu selected? }
end; { 1 }
2 :
begin
l.state := 1
end; { 2 }
else
l.state := 0;
end; { Case }
end; { Re-entrant Section }
{Section 2: Afirst - Tasks to perform only once}
if act = Afirst then begin //Initialize local state and other variables
wrterr('iniBrowser Macro - BETA Version 1.0.0.2');
l.state := 1;
end
{Section 4: Alast - If your macro has been interrupted by user action}
else if act = Alast then begin
//If you're going to get blown off the stack...
//(i.e.) the user pressed a hotkey,
//then this is your last chance to clean up temporary data.
end
{Section 1: AlSize - Allocate memory on stack for local variables}
else if act = AlSize then begin
SetLocalSize(sizeof(l^));
end;
if act <> alsize then begin { Action section - Invoke the Dispatcher }
case l.state of
1 :
begin { 1: Main Menu }
wrtlvl('iniBrowser'); //Set Menu Title
lblsinit;
lblset(1, 'DCADWIN', 'Browse and edit DCADWIN.INI');
lblson1;
getpoint(l.getp, retval);
{Dispatcher will call as soon as it has control, go to Aagain: 1}
end; { 1 }
2:
begin
iniForm := TiniForm.Create(Application);
iniForm.ShowModal;
iniForm.Free;
callNone(retval);{ You have to ask the Dispatcher to do something. }
{ In this case, ask the dispatcher to do nothing. }
{Dispatcher will call as soon as it has control, go to Aagain: 2}
end; { 2 }
else
retval := XDone; //Don't go back to Aagain
end; { Case }
end; { Action section }
Result := retval;
end; { iniBrowser_main }
//End Main Function (Re-entrant State Machine)
function Main(dcalstate : asint; act : action; pl, pargs : Pointer) : wantType; stdcall;
begin
case dcalstate of
XDcalStateBegin : Result := iniBrowser_main(act, pl, pargs);
else
Result := XDone;{Necessary}
end;
end;
//End of Main Function (Re-entrant State Machine)
exports
Main;{This is the entry function that will be called by DataCAD.
All DCAL Dlls will have this function.}
begin
end.
Here is the source code to the main form unit 'iniBrowserForm.pas':
Code: Select all
unit iniBrowserForm;
interface
uses
// Delphi Units
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ValEdit, inifiles, FileCtrl,
// DCAL for Delphi Units
UConstants, UInterfaces, UInterfacesRecords, URecords, UVariables;
type
TiniForm = class(TForm)
BtnLoadINI: TButton;
EditINI: TEdit;
gbSection: TGroupBox;
gbKeys: TGroupBox;
lbINISection: TListBox;
vlINIKeys: TValueListEditor;
DlgOpenINI: TOpenDialog;
procedure BtnLoadINIClick(Sender: TObject);
procedure lbINISectionClick(Sender: TObject);
procedure vlINIKeysEditButtonClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure vlINIKeysValidate(Sender: TObject; ACol, ARow: Integer; const KeyName, KeyValue: string);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
iniForm: TiniForm;
Ini: TIniFile;
implementation
{$R *.dfm}
procedure TiniForm.BtnLoadINIClick(Sender: TObject);
begin
DlgOpenINI.Execute();
EditINI.Text := Trim((DlgOpenINI.FileName));
Ini := TIniFile.Create(EditINI.Text);
Ini.ReadSections(lbINISection.Items);
lbINISection.Sorted := True;
// Ini.free;
end;
function getvalue(tempdir: string): string;
var
c, d, e: byte;
pathdir: string;
begin
if tempdir <> '' then begin
c := length(tempdir);
d := length(tempdir);
while (tempdir[c] <> '=') do begin
dec(c);
end;
inc(c);
pathdir := '';
for e := c to d do begin
pathdir := pathdir + tempdir[e];
end;
end;
result := pathdir
end;
procedure TiniForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(Ini) then
Ini.Free;
end;
procedure TiniForm.FormCreate(Sender: TObject);
var
path : ShortString;
begin
DlgOpenINI.Filter := 'INI files (*.ini)|*.ini';
getpath(path, Pathinstall);
EditINI.Text := path + 'DCADWIN.INI';
Ini := TIniFile.Create(EditINI.Text);
Ini.ReadSections(lbINISection.Items);
lbINISection.Sorted := True;
end;
procedure TiniForm.lbINISectionClick(Sender: TObject);
var
id, count, x: Integer;
Ini: TIniFile;
idname: string;
sl1, sl2: Tstringlist;
svValue1, svValue2: string;
slTF: Tstringlist;
begin
vlINIKeys.Strings.Clear;
id := lbINISection.ItemIndex;
idname := lbINISection.Items.Strings[id];
sl1 := Tstringlist.Create;
sl2 := Tstringlist.Create;
slTF := Tstringlist.Create;
Ini := TIniFile.Create(EditINI.Text);
slTF.Add('TRUE');
slTF.Add('FALSE');
with Ini do begin
readsection(idname, sl1);
readsectionvalues(idname, sl2);
end;
count := sl1.count;
for x := 0 to count - 1 do begin
vlINIKeys.InsertRow(sl1.Strings[x], getvalue(sl2.Strings[x]), True);
svValue1 := sl1.Strings[x];
svValue2 := getvalue(sl2.Strings[x]);
if SysUtils.directoryExists(svValue2) then
vlINIKeys.ItemProps[x].EditStyle := esEllipsis;
if (svValue2 = 'TRUE') or (svValue2 = 'FALSE') then begin
vlINIKeys.ItemProps[x].EditStyle := esPickList;
vlINIKeys.ItemProps[x].ReadOnly := True;
vlINIKeys.ItemProps[x].PickList := slTF;
end;
end;
// Ini.Free;
sl1.Free;
sl2.Free;
slTF.Free;
end;
procedure TiniForm.vlINIKeysEditButtonClick(Sender: TObject);
const
SELDIRHELP = 1000;
var
dir: string;
PRow: Integer;
svPath: string;
svSection: string;
begin
PRow := vlINIKeys.Row;
svPath := vlINIKeys.Keys[PRow];
dir := vlINIKeys.Values[svPath];
if SelectDirectory(dir, [
{ sdAllowCreate, sdPerformCreate, sdPrompt } ], SELDIRHELP) then begin
vlINIKeys.Values[svPath] := dir;
svSection := lbINISection.Items.Strings[lbINISection.ItemIndex];
Ini.WriteString(svSection, vlINIKeys.Keys[PRow], dir + '\');
vlINIKeys.Values[svPath] := dir + '\';
end;
end;
procedure TiniForm.vlINIKeysValidate(Sender: TObject; ACol, ARow: Integer; const KeyName, KeyValue: string);
var
svSection: string;
begin
svSection := lbINISection.Items.Strings[lbINISection.ItemIndex];
Ini.WriteString(svSection, KeyName, KeyValue);
end;
end.