![]() |
|
|
#16
|
|||
|
|||
|
Цитата:
1. именно так и делаю выножу в dll обработку которая требуется редко. и дело не в занимаемой памяти. Тут все проще чем меньше прога весит в оперативе тем быстрее и стабильнее она работает. 2. Что сделать? снизить затраты в ЦП и памяти? 3. для увеличение быстродействия не создавайте громоских процеду, а старайтесь делить на небольшие процы и функции. Например чтение из реестра можно написать двумя способами. Но второй показал более оптимальные параметры и меньшее время (При многократнм обращении). Способ 1: Код:
const cKeyRoot: HKEY = HKEY_CURRENT_USER ; cKey: string = '\Software\MyProg'; Var Reg: TRegistry; function GetStrReg(RootKey:HKey;Key:string):string; begin Reg:=TRegistry.Create; Reg.RootKey:=RootKey; Reg.OpenKey(Key,False); Result:=Reg.ReadString(Param); Reg.CloseKey; Reg.Free; end; Второй способ Код:
const cKeyRoot: HKEY = HKEY_CURRENT_USER ; cKey: string = '\Software\ibc'; var Reg: Tregistry procedure CreateReg(RootKey: HKEY;Key:string); begin Reg:=TRegistry.Create; Reg.RootKey:=RootKey; Reg.OpenKey(Key,false); end; procedure FreeReg; begin Reg.CloseKey; Reg.Free; end; function ReadIntReg(RootKey:HKEY; Key,Param: string): integer; begin CreateReg(RootKey,Key,False); Result:=Reg.ReadInteger(Param); FreeReg; end; //---------------------------------------------------------- function ReadStrReg(RootKey:HKEY; Key,Param: string): String; begin CreateReg(RootKey,Key,False); Result:=Reg.ReadString(Param); FreeReg; end; К тому же второй более гибкий Последний раз редактировалось dmdx, 24.09.2008 в 13:08. |
|
#17
|
|||
|
|||
|
можно пример выноса в длл..если можно подробно
|
|
#18
|
|||
|
|||
|
Цитата:
на форуме куча материала по поводу использования динамических библиотек. одну или две я сам поднимал поищи. вот пример dll Код:
library FunDll;
uses
SysUtils,
dialogs,
Classes;
{$R *.res}
procedure ShowMsg(text: pchar); stdcall; export;
begin
ShowMessage(text);
end;
function Summ(x: integer; y: integer):integer; stdcall; export;
begin
result:=x+y;
end;
exports
ShowMsg name 'ShowMsg',
Summ name 'Summ';
begin
end.
project code Код:
unit uProgMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TSumm = function (x: integer; y: integer ): integer; stdcall;
TShowMgs = procedure (text: pchar); stdcall;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
s: string = 'Welcome';
var
dllHandle: THandle;
ShowMsg: TShowMgs;
begin
@ShowMsg:=nil;
dllHandle:=LoadLibrary(pchar('FunDll.dll'));
if dllHandle=0 then
exit;
@ShowMsg:=GetProcAddress(dllHandle,'ShowMsg');
if @ShowMsg = nil then
exit;
ShowMsg(pchar(s));
@ShowMsg:=nil;
FreeLibrary(dllHandle);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
dllHandle: THandle;
Suma: TSumm;
begin
@Suma:=nil;
dllHandle:=LoadLibrary(pchar('FunDll.dll'));
if dllHandle<32 then
exit;
@Suma:=GetProcAddress(dllHandle,PChar('Summ'));
if @Suma=nil then
exit;
ShowMessage(inttostr(Suma(2,5)));
@Suma:=nil;
FreeLibrary(dllHandle);
end;
end.
|
|
#19
|
|||
|
|||
|
Цитата:
на форуме куча материала по поводу использования динамических библиотек. одну или две я сам поднимал поищи. вот пример dll Код:
library FunDll;
uses
SysUtils,
dialogs,
Classes;
{$R *.res}
procedure ShowMsg(text: pchar); stdcall; export;
begin
ShowMessage(text);
end;
function Summ(x: integer; y: integer):integer; stdcall; export;
begin
result:=x+y;
end;
exports
ShowMsg name 'ShowMsg',
Summ name 'Summ';
begin
end.
project code Код:
unit uProgMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TSumm = function (x: integer; y: integer ): integer; stdcall;
TShowMgs = procedure (text: pchar); stdcall;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
s: string = 'Welcome';
var
dllHandle: THandle;
ShowMsg: TShowMgs;
begin
@ShowMsg:=nil;
dllHandle:=LoadLibrary(pchar('FunDll.dll'));
if dllHandle=0 then
exit;
@ShowMsg:=GetProcAddress(dllHandle,'ShowMsg');
if @ShowMsg = nil then
exit;
ShowMsg(pchar(s));
@ShowMsg:=nil;
FreeLibrary(dllHandle);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
dllHandle: THandle;
Suma: TSumm;
begin
@Suma:=nil;
dllHandle:=LoadLibrary(pchar('FunDll.dll'));
if dllHandle<32 then
exit;
@Suma:=GetProcAddress(dllHandle,PChar('Summ'));
if @Suma=nil then
exit;
ShowMessage(inttostr(Suma(2,5)));
@Suma:=nil;
FreeLibrary(dllHandle);
end;
end.
|