DDE 메시지를 통해서 엑셀과 데이터를 연동하는 프로그램인데여.. 컴파일은 되는데 엑셀로 데이터가 넘어가질 않네여... 잘 모르겠지만 엑셀에서 WM_DDE_REQUEST 메시지가 넘어 오는 것 같지 않은데여...
엑셀의 셀에 = server1|topic1!item1이라고 해놨구요..
고수님들 부탁드립니다... 도와주세여~~
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure WndProc(var Message: TMessage); override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.WndProc(var Message: TMessage);
var
szApp, szTopic, szItem : PChar;
aApp, aTopic, aItem : ATOM;
WhichItem : PChar;
hData : HWND;
lpData : ^DDEDATA;
DDElParam : LPARAM;
begin
GetMem(szApp, 255);
GetMem(szTopic, 255);
GetMem(szItem, 255);
GetMem(WhichItem, 255);
Getmem(lpData, sizeof(lpData^));
case Message.Msg of
WM_DDE_INITIATE:
begin
GlobalGetAtomName(LOWORD(message.lParam), szApp, 255);
GlobalGetAtomName(HIWORD(message.lParam), szTopic, 255);
if (CompareStr(szApp, 'server1') = 0) and (CompareStr(szTopic, 'topic1') = 0) then
begin
aApp := GlobalAddAtom('server1');
aTopic := GlobalAddAtom('topic1');
SendMessage(HWND(message.wParam), WM_DDE_ACK, WPARAM(Handle), MAKELPARAM(aApp, aTopic));
GlobalDeleteAtom(aApp);
GlobalDeleteAtom(aTopic);
end;
end;
WM_DDE_REQUEST:
begin
UnpackDDElParam(WM_DDE_REQUEST, message.lParam, PUINT(@Format), PUINT(@aItem));
FreeDDElParam(WM_DDE_REQUEST, message.lParam);
GlobalGetAtomName(aItem, szItem, 255);
GlobalDeleteAtom(aItem);
if (CompareStr(szItem, 'item1') = 0) then
WhichItem := PChar('item1에 대한 데이터');
// 데이터를 조립한다
if (WhichItem <> Nil) then begin
hData := GlobalAlloc(GMEM_MOVEABLE, sizeof(DDEDATA) + LongInt(strlen(WhichItem)) +2);
lpData := GlobalLock(hData);
lpData^.cfFormat := CF_TEXT;
//lpData^.fAckReq := TRUE;
//lpData^.fRelease := TRUE;
//lpData^.fResponse := TRUE;
lpData^.Flags := $f;
StrCopy(PChar(@lpData^.Value), WhichItem); //???
GlobalUnlock(hData);
// 데이터를 엑셀(클라이언트)에 보낸다
aItem := GlobalAddAtom(szItem);
DDElParam := PackDDElParam(WM_DDE_DATA, UINT(hData), aItem);
if not(PostMessage(HWND(message.WParam), WM_DDE_DATA, WPARAM(Handle) ,DDElParam)) then begin
GlobalFree(hData);
GlobalDeleteAtom(aItem);
FreeDDElParam(WM_DDE_DATA, DDElParam);
end
end;
end;
end;
FreeMem(szApp);
FreeMem(szTopic);
FreeMem(szItem);
FreeMem(WhichItem);
FreeMem(lpData);
inherited;
end;
end.
다음 컴포넌트를 참고하세요
문제가 해결되길 빕니다.
http://www.torry.net/vcl/reports/reportdesigners/agexcelreport.zip