[talking to self]
was in ObjectPascal, maybe better luck here...
Hello, fellow D programmer
I am trying to get my application to pass parameters to the previous
instance if it exists by DDE. I can get my DDE ClientConv to establish
a link, but the PokeData function does not pass data and always
returns false. Below is a snippet of of my code. I hope someone can
help me track down the problem. I am using D1.
TIA and Happy New Year.
___________________________________________________________________
Main Form Unit
:
type
TAppForm = class(TForm)
:
public
DDEServerItem : TDDEServerItem;
DDEServerConv: TDDEServerConv;
end;
const
AppTitle = 'MyProgram';
DDETopic = 'MyDDESrv';
DDEItem = 'MyDDEItem';
DDEService = 'Project1'; { application name w/o .exe extension}
:
procedure TAppForm.FormCreate(Sender: TObject);
var
i: integer;
begin
DDEServerItem := TDDEServerItem.Create(Application);
DDEServerItem.Name := DDEItem;
DDEServerConv := TDDEServerConv.Create(Application);
DDEServerConv.Name := DDETopic;
DDEServerItem.ServerConv := DDEServerConv;
DDEServerItem.OnPokeData := PokeDDEData;
end;
________________________________________________________________
Project Unit:
:
function LimPrvInstance: boolean;
var
DDEClient: TDDEClientItem;
DDEClientConv: TDDEClientConv;
PStr: PChar;
i: integer;
begin
result := false;
if FindWindow('TApplication', AppTitle) <> 0 then
try
DDEClient:= TDDEClientItem.Create(Application);
DDEClientConv := TDDEClientConv.Create(Application);
DDEClientConv.DDEService := DDEService;
DDEClientConv.DDETopic := DDETopic;
DDEClientConv.ServiceApplication := 'Project1';
DDEClient.DDEConv:= DDEClientConv;
DDEClient.DDEItem := DDEItem;
DDEClientConv.SetLink(DDEService, DDETopic);
******* if DDEClientConv.PokeData(DDEItem, 'garbage' ) then
******* showmessage('true') else
******* showmessage('false'); <--+
|
^
+----<- always false ???
for i:= 1 to ParamCount do
DDEClientConv.PokeData(DDETopic,
StrPCopy(pStr, ParamStr(i)) );
DDEClientConv.CloseLink;
finally
DDEClient.Free;
DDEClientConv.Free;
result := true;
end;
end;
begin
if LimPrvInstance then halt;
{ change application title after DDE to avoid inifinit
recursion }
Application.Title := AppTitle;
Application.CreateForm(TAppForm, AppForm);
{ process parameters }
for i := 1 to ParamCount do AppForm.ExecuteMacro(ParamStr(i));
Application.Run;
end;