Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.04.04;
Скачать: CL | DM;

Вниз

Как передать как параметр - ссылку на функцию?   Найти похожие ветки 

 
ПрогерШ   (2004-03-18 09:59) [0]

Мастера, очень часто приходится дублировать код - подготовка отчета, выполнение запроса к БД, прочие длительные операции... Хочу сделать функцию, в которую я бы передавал тело нужных операций, а каркас был бы всегда одним и тем же.

function SplashProcces(TextMessage: string; {??? - ссылку на тело}):int;
var Splash: TForm;
begin
Screen.Cursor := crHourGlass;
Splash := ShowSplashWindow(Application.Icon,TextMessage,False, Application.MainForm);
try
  //???
finally
 Splash.Free;
 Screen.cursor := crDefault;
end;
end;

Подскажите что надо писать вместо - ???


 
Digitman ©   (2004-03-18 10:07) [1]

type
TFunc = function: SomeType;
...

function FuncToBeCalled: SomeType;
begin
 Result := SomeValue;
end;

function SomeFunc(Func: TFunc):SomeType;
begin
 Result := Func;
end;

...

SomeResult := SomeFunc(@FuncToBeCalled);


 
ПрогерШ   (2004-03-18 10:10) [2]

Сенькс огромное!


 
ПрогерШ   (2004-03-18 10:39) [3]

Error - Variable required

TFunction = function(Data: TpFIBDataSet; FetchAll: boolean):integer;
...
function Tdm.ReopenFormWithData(SplashText: string; InFunction: TFunction):integer;
var Splash: TForm;
begin
 Screen.Cursor := crHourGlass;
 Splash := ShowSplashWindow(Application.Icon,SplashText,
 False, Application.MainForm);
 try
   Result := InFunction;
 finally
   Splash.Free;
   Screen.Cursor := crDefault;
 end;
end;
...
function Tdm.DataCloseOpen(Data: TpFIBDataSet; FetchAll: boolean):integer;
begin
 Data.CloseOpen(FetchAll);
end;
...
Res := SplashProcess(SplashTextSearch,@DataCloseOpen(dsSearch,false));//Error


 
ПрогерШ   (2004-03-18 10:41) [4]

конечно же не
function Tdm.ReopenFormWithData(SplashText: string; InFunction: TFunction):integer;
а
function Tdm.SplashProcess(SplashText: string; InFunction: TFunction):integer;


 
Erik ©   (2004-03-18 10:51) [5]

Все просто, напиши так:
TFunction = procedure(Data: TpFIBDataSet; FetchAll: boolean) of object;


 
Плохиш   (2004-03-18 10:58) [6]

>ПрогерШ   (18.03.04 10:39) [3]
> TFunction = function(Data: TpFIBDataSet; FetchAll: boolean):integer;


>  try
>    Result := InFunction;
>  finally

Параметры за тебя Пушкин будет задавать?


 
ПрогерШ   (2004-03-18 11:35) [7]

Как правильно туда передать параметры - не выходит... :(


 
Плохиш   (2004-03-18 11:45) [8]


> Res := SplashProcess(SplashTextSearch,@DataCloseOpen(dsSearch,false));

А это ты ешё сто такие написал?

PS. Что в справке про использование процедурных типов западло прочитать?


 
ПрогерШ   (2004-03-18 12:11) [9]

function Tdm.SplashProcess(SplashText: string; InFunction: TFunction):integer;
var Splash: TForm;
begin
 Screen.Cursor := crHourGlass;
 Splash := ShowSplashWindow(Application.Icon,SplashText,
 False, Application.MainForm);
 try
   Result := InFunction(Data, FetchAll);//Undeclared identifier: Data
 finally
   Splash.Free;
   Screen.Cursor := crDefault;
 end;
end;

Мастаки что не так?


 
Smithson ©   (2004-03-18 12:12) [10]

Ну и что такое по-твоему Data?
Компилятор мысли читать не умеет!


 
ПрогерШ   (2004-03-18 12:17) [11]

TFunction = function(Data: TpFIBDataSet; FetchAll: boolean):integer;
...
function DataCloseOpen(Data: TpFIBDataSet; FetchAll: boolean):integer;
function SplashProcess(SplashText: string; InFunction: TFunction;
   Data: TpFIBDataSet; FetchAll: boolean):integer;
...
function Tdm.DataCloseOpen(Data: TpFIBDataSet; FetchAll: boolean):integer;
begin
 Data.CloseOpen(FetchAll);
 Result := 1;
end;
...
function Tdm.SplashProcess(SplashText: string; InFunction: TFunction;
Data: TpFIBDataSet; FetchAll: boolean):integer;
var Splash: TForm;
begin
 Screen.Cursor := crHourGlass;
 Splash := ShowSplashWindow(Application.Icon,SplashText,
 False, Application.MainForm);
 try
   Result := InFunction(Data, FetchAll);
 finally
   Splash.Free;
   Screen.Cursor := crDefault;
 end;
end;
...
Res := SplashProcess(SplashTextSearch,@DataCloseOpen,dsSearch, true);//Error- Variable required



Страницы: 1 вся ветка

Текущий архив: 2004.04.04;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.031 c
14-1078465796
Dimich1978
2004-03-05 08:49
2004.04.04
Борьба с вирусами


1-1079199559
John Doe
2004-03-13 20:39
2004.04.04
Файлы файлы файлы!!


1-1079620489
Erik
2004-03-18 17:34
2004.04.04
Как определить масив констант?


8-1070016737
X-Disa
2003-11-28 13:52
2004.04.04
Размер картинки


6-1074585782
KIE
2004-01-20 11:03
2004.04.04
Два компа по удаленке ...