Форум: "Основная";
Текущий архив: 2004.04.04;
Скачать: [xml.tar.bz2];
ВнизКак передать как параметр - ссылку на функцию? Найти похожие ветки
← →
ПрогерШ (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;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.037 c