Re:MORE THAN ONE COPY OF THE MAIN FORM (MAIN FORM.EXE)
const
SECTION = 'NUS_EDI';
section_key = 'Working';
function write_working(const lwork: boolean; FIniFile: TRegIniFile):
boolean;
var
line_ : string;
begin
Result:= false;
if assigned(FIniFile) then
with FIniFile do
begin
if OpenKey(section,true) then
begin
WriteBool(section_key,'Working',lwork);
if lwork then
WriteString(section_key,'Date Working',DateTimeToStr(Now));
CloseKey;
Result:= true
end
else begin
if lwork then
line_:= 'OpenKey false. Working not set'
else
line_:= 'OpenKey false. Working not cleared';
Raise Ewrite_err.Create_write(line_,true,48,0)
end
end
end;
function read_working(var FIniFile: TRegIniFile): boolean;
begin
Result:= assigned(FIniFile);
if Result then
with FIniFile do
begin
if OpenKey(section,false) then
begin
Result:= ReadBool(section_key,'Working',false);
if Result then
begin
line_:= ReadString(section_key,'Date Working','');
ThisDate:= StrToDateTime(line_);
Result:= Now - ThisDate <= 1/24 // okay if an hour apart
end;
CloseKey;
if Result and not l_auto then
begin
bel;
Result:= not confirm('Clear working key?')
end;
if Result then
begin
FIniFile:= nil; //Close will not set working to false
Raise EWork.Create('Working previously set ' + line_,false)
end
else
write_working(true,FIniFile)
end
else
Raise Ewrite_err.Create_write('OpenKey false',true,48,0)
end
end;
Quote
Rakam Limbu Begha wrote:
> Dear Sanford,
> How it is done? I am quite novice in matters of playing with registry.
> I would very glad if you could help in this matter.
> Sincerely,
> rakam
> --
> "Sanford Aranoff" <saran...@nusinc.com> wrote in message
> news:3B14F72D.FE6E3E16@nusinc.com...
> > I write variables to the registry. This gives me more control than the
> > mutex approach. With the registry approach, I can decide to ignore the
> > first program if it is too old. E.g., if the first program started
> > yesterday, then it is okay to run the second exe. Furthermore, the
> > registry approach permits me to write to a log file so that I can
> > monitor what is happening.
> > The code is confusing, and I'd be glad to share it.