在dll中修改调用程序的application.title(200分)

  • 主题发起人 zzutlink
  • 开始时间
Z

zzutlink

Unregistered / Unconfirmed
GUEST, unregistred user!
我在程序主窗体的onCreate事件中调用dll中的方法,利用该方法对程序的application.title进行修改,请问如何实现?

我将application作为参数传递,直接就报错,如果传递application.handle,却得不到想要的效果,麻烦大家帮忙,写出几句关键代码,谢谢。
 
你找找dll的回调函数看看。可能对你有帮助
 
有如下几个办法:
1、在主窗体中调用DLL的方法,返回文本然后再设置为Application.Title
Application.Title := DLLGetAppTitle; //在主程序中执行
2、传入Application.Handle给Dll,DLL内用API来设置Title: SetWindowText
SetWindowText(AppHandle, 'Title');
3、传入Application对象,直接修改Application.Title,但DLL及EXE都要引用ShareMem单元
Application.Title := 'Title';
 
procedure setTitle(app: TApplication; title: string);stdcall;
begin
app.title := title;
end;
不行?不会吧?我的完全正常。
----------------------------------
library mydll;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
forms;

{$R *.res}

procedure setTitle(app: TApplication; title: string);stdcall;
begin
app.title := title;
end;

exports
setTitle;

begin
end.
-----------------------------------
unit untMain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

procedure setTitle(app: TApplication; title: string);stdcall;
external 'mydll.dll' name 'setTitle';

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
setTitle(Application, 'ok');
end;

end.

 
多人接受答案了。
 
顶部