home *** CD-ROM | disk | FTP | other *** search
- { FormulaBuilder }
- { YGB Software, Inc. }
- { Copyright 1995 Clayton Collie }
- { All rights reserved }
-
-
- {*
- * External Function Module for
- * FormulaBuilder 1.00 Main Demo
- * Copyright 1995 Clayton Collie
- * All Rights Reserved
- *}
- {$F+,V-}
- unit extfunc;
- interface
-
- Procedure RegisterFunctions;
- Procedure UnregisterFunctions;
-
- implementation
- uses sysutils,controls,forms,messages,
- dialogs,
- Fbcalc,
- winprocs,wintypes;
-
- const
- installed : boolean = false;
- constinstalled : boolean = false;
-
- var
- fnCopy, fnRename, fnExec,
- fnExecWait, fnDelete,
- fnErrorMsg, fnMsgBox,
- fnBeep, fnYesNo,
- fnYesNoCancel, fnInputstring : integer;
-
-
-
- (* Thanks to stidolph@magnet.com (David Stidolph) for the following *)
-
- function FileCopy(source,dest: String): Boolean;
- var
- fSrc,fDst,len: Integer;
- size: Longint;
- buffer: packed array [0..2047] of Byte;
- begin
- Result := False; { Assume that it WONT work }
- if source <> dest then begin
- fSrc := FileOpen(source,fmOpenRead);
- if fSrc >= 0 then begin
- size := FileSeek(fSrc,0,2);
- FileSeek(fSrc,0,0);
- fDst := FileCreate(dest);
- if fDst >= 0 then begin
- while size > 0 do begin
- len := FileRead(fSrc,buffer,sizeof(buffer));
- FileWrite(fDst,buffer,len);
- size := size - len;
- end;
- FileSetDate(fDst,FileGetDate(fSrc));
- FileClose(fDst);
- FileSetAttr(dest,FileGetAttr(source));
- Result := True;
- end;
- FileClose(fSrc);
- end;
- end;
- end;
-
-
- {----------------------------------------------------
- Name: WinExecAndWait function
- Declaration: WinExecAndWait(Path : Pchar; Visibility : word) : word;
- Unit: UtilBox
- Code: S
- Date: 02/05/95
- Description: Execute a Windows or DOS program and wait until it
- returns. In the meantime, continue to process
- Window messages. ( Thanks to Lar Mader. )
- -----------------------------------------------------}
-
- function WinExecAndWait(Path : Pchar; Visibility : word) : word;
- var
- InstanceID : THandle;
- Msg : TMSg;
- begin
- InstanceID := WinExec(Path,Visibility);
- if InstanceID < 32 then { a value less than 32 indicates an Exec error }
- WinExecAndWait := InstanceID
- else
- repeat
- while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
- if Msg.Message = WM_QUIT then
- halt(Msg.wParam);
- TranslateMessage(Msg);
- DispatchMessage(Msg);
- end;
- until GetModuleUsage(InstanceID) = 0;
- end;
-
-
- Procedure CopyFileProc(paramcount : byte;
- Const params : TActParamList;
- var RetValue : TValueRec;
- var nErrorCode : integer;
- exprData : longint); export;
- begin
- retvalue.vBoolean := FileCopy(params[0].vpString^,params[1].vpString^);
- end;
-
-
- Procedure RenFileProc(bParamcount : byte;
- Const params : TActParamList;
- var RetValue : TValueRec;
- var nErrorCode : integer;
- exprdata : longint); export;
- begin
- retvalue.vBoolean := RenameFile(params[0].vpString^,params[1].vpString^);
- end;
-
-
- Procedure RunFileProc(bParamcount : byte;
- Const params : TActParamList;
- var RetValue : TValueRec;
- var nErrorCode : integer;
- exprdata : longint); export;
- var visibility : word;
- s : string[90];
- begin
- if (bParamcount = 1) then
- visibility := SW_MAXIMIZE
- else
- if params[0].vInteger < 0 then
- nErrorCode := EXPR_DOMAIN_ERROR
- else
- begin
- visibility := params[0].vInteger;
- s := params[0].vpString^ + #0;
- retvalue.vInteger := WinExec(@s[1],visibility);
- end;
- end;
-
-
-
- Procedure ExecWaitProc(bParamcount : byte;
- Const params : TActParamList;
- var RetValue : TValueRec;
- var nErrorCode : integer;
- exprdata : longint); export;
- var visibility : word;
- s : string[90];
- begin
- if (bParamcount = 1) then
- visibility := SW_MAXIMIZE
- else
- if params[0].vInteger < 0 then
- nErrorCode := EXPR_DOMAIN_ERROR
- else
- begin
- visibility := params[0].vInteger;
- s := params[0].vpString^ + #0;
- retvalue.vInteger := WinExecAndWait(@s[1],visibility);
- end;
- end;
-
-
- {* Delete a file *}
- Procedure DeleteFileProc(bParamcount : byte;
- Const params : TActParamList;
- var RetValue : TValueRec;
- var nErrorCode : integer;
- exprdata : longint); export;
- begin
- retvalue.vBoolean := DeleteFile(params[0].vpString^);
- end;
-
-
- {* Show an error message dialog box *}
- Procedure DispErrorProc(paramcount : byte;
- const params : TActParamList;
- var retvalue : TValueRec;
- var nErrorCode : integer;
- exprdata : longint); export;
- begin
- MessageDlg(params[0].vpString^,mtError, [mbOk], 0);
- end;
-
-
- Procedure MessageBoxProc(paramcount : byte;
- const params : TActParamList;
- var retvalue : TValueRec;
- var nErrorCode : integer;
- exprdata : longint); export;
- begin
- MessageDlg(params[0].vpString^,mtInformation, [mbOk], 0);
- end;
-
-
- Procedure BeepProc(paramcount : byte;
- const params : TActParamList;
- var RetValue : TValueRec;
- var nErrorCode : integer;
- exprdata : longint);
- begin
- if paramcount = 0 then
- MessageBeep(mb_iconhand)
- else
- MessageBeep(params[0].vInteger);
- end;
-
-
- procedure YesNoProc(paramcount : byte;
- const Params : TActParamlist;
- var Retvalue : TValueRec;
- var iErrcode : integer;
- exprdata : longint); export;
- begin
- Retvalue.vBoolean := MessageDlg(params[0].vpString^,
- mtConfirmation,
- [mbYes, mbNo], 0) = mrYes;
- end;
-
-
- procedure YesNoCancelProc(paramcount : byte;
- const Params : TActParamlist;
- var Retvalue : TValueRec;
- var iErrcode : integer;
- exprdata : longint); export;
- var tmp : integer;
- begin
- case MessageDlg(params[0].vpString^,mtConfirmation,[mbYes,mbNo,mbCancel],0)of
- mrYes : retvalue.vInteger := 1;
- mrNo : retvalue.vInteger := 2;
- mrCancel : retvalue.vInteger := 3;
- end;
- end;
-
-
- procedure InputStringProc(paramcount : byte;
- const Params : TActParamlist;
- var Retvalue : TValueRec;
- var iErrcode : integer;
- exprdata : longint); export;
- var tmpstr : string;
- begin
- tmpstr := params[2].vpString^;
- if InputQuery( Params[0].vpString^, params[1].vpString^, tmpstr ) then
- begin
- tmpstr := tmpstr + #0;
- retvalue.vpString := FBCreateString(@tmpstr[1]);
- end;
- end;
-
-
-
-
-
-
- {* Install some standard Windows.h constants *}
- Procedure RegisterConstants;
- begin
- if constInstalled then exit;
- FBAddNumericConstant('SW_HIDE',SW_HIDE);
- FBAddNumericConstant('SW_SHOWNORMAL',SW_SHOWNORMAL);
- FBAddNumericConstant('SW_NORMAL',SW_NORMAL);
- FBAddNumericConstant('SW_SHOWMINIMIZED',SW_SHOWMINIMIZED);
- FBAddNumericConstant('SW_SHOWMAXIMIZED',SW_SHOWMAXIMIZED);
- FBAddNumericConstant('SW_MAXIMIZE',SW_MAXIMIZE);
- FBAddNumericConstant('SW_SHOWNOACTIVATE',SW_SHOWNOACTIVATE);
- FBAddNumericConstant('SW_SHOW',SW_SHOW);
- FBAddNumericConstant('SW_MINIMIZE',SW_MINIMIZE);
- { FBAddNumericConstant('SW_SHOWMINNOACTIVE',SW_MINNOACTIVE); }
- FBAddNumericConstant('SW_SHOWNA',SW_SHOWNA);
- FBAddNumericConstant('SW_RESTORE',SW_RESTORE);
-
- FBAddNumericConstant('MB_OK',$0000);
- FBAddNumericConstant('MB_OKCANCEL',$0001);
- FBAddNumericConstant('MB_ABORTRETRYIGNORE',$0002);
- FBAddNumericConstant('MB_YESNOCANCEL',$0003);
- FBAddNumericConstant('MB_YESNO',$0004);
- FBAddNumericConstant('MB_RETRYCANCEL',$0005);
- FBAddNumericConstant('MB_TYPEMASK',$000F);
- FBAddNumericConstant('MB_ICONHAND',$0010);
- FBAddNumericConstant('MB_ICONQUESTION',$0020);
- FBAddNumericConstant('MB_ICONEXCLAMATION',$0030);
- FBAddNumericConstant('MB_ICONASTERISK',$0040);
- FBAddNumericConstant('MB_ICONMASK',$00F0);
-
- FBAddNumericConstant('MB_ICONINFORMATION',MB_ICONASTERISK);
- FBAddNumericConstant('MB_ICONSTOP',MB_ICONHAND);
-
- FBAddNumericConstant('MB_DEFBUTTON1',$0000);
- FBAddNumericConstant('MB_DEFBUTTON2',$0100);
- FBAddNumericConstant('MB_DEFBUTTON3',$0200);
- FBAddNumericConstant('MB_DEFMASK',$0F00);
-
- FBAddNumericConstant('MB_APPLMODAL',$0000);
- FBAddNumericConstant('MB_SYSTEMMODAL',$1000);
- FBAddNumericConstant('MB_TASKMODAL',$2000);
-
- FBAddNumericConstant('MB_NOFOCUS',$8000);
-
- {* Standard dialog button IDs *}
- FBAddNumericConstant('IDOK',IDOK);
- FBAddNumericConstant('IDCANCEL',IDCANCEL);
- FBAddNumericConstant('IDABORT',IDABORT);
- FBAddNumericConstant('IDRETRY',IDRETRY);
- FBAddNumericConstant('IDIGNORE',IDIGNORE);
- FBAddNumericConstant('IDYES',IDYES);
- FBAddNumericConstant('IDNO',IDNO);
- constinstalled := true;
- end;
-
-
- Procedure RegisterFunctions;
- begin
- if installed then exit;
- InitFBuilder;
- fnCopy := FBRegisterFunction('copy',vtBOOLEAN,'ss',2,CopyfileProc);
- fnRename := FBRegisterFunction('rename',vtBOOLEAN,'ss',2,RenFileProc);
- fnExec := FBRegisterFunction('exec',vtInteger,'si',1,RunFileProc);
- fnExecWait := FBRegisterFunction('execwait',vtInteger,'si',1,ExecWaitProc);
- fnDelete := FBRegisterFunction('delete',vtBOOLEAN,'s',1,DeleteFileProc);
- fnErrorMsg := FBRegisterFunction('errormsg',vtInteger,'s',1,DispErrorProc);
- fnMsgBox := FBRegisterFunction('msgbox',vtInteger,'s',1,MessageBoxProc);
- fnBeep := FBRegisterFunction('beep',vtInteger,'i',1,BeepProc);
- fnYesNo := FBRegisterFunction('yesno',vtInteger,'s',1,YesNoProc);
- fnYesNoCancel := FBRegisterFunction('yesnocancel',vtInteger,'s',1,YesNoCancelProc);
- fnInputString := FBRegisterFunction('inputstring',vtString,'sss',3,InputstringProc);
- RegisterConstants;
- installed := true;
- end;
-
-
- Procedure UnregisterFunctions;
- begin
- If not FBLoaded then exit;
- FBUnRegisterFunction(fnCopy);
- FBUnRegisterFunction(fnRename);
- FBUnRegisterFunction(fnExec);
- FBUnRegisterFunction(fnExecWait);
- FBUnRegisterFunction(fnDelete);
- FBUnRegisterFunction(fnErrorMsg);
- FBUnRegisterFunction(fnMsgBox);
- FBUnRegisterFunction(fnBeep);
- FBUnRegisterFunction(fnYesNo);
- FBUnRegisterFunction(fnYesNoCancel);
- FBUnRegisterFunction(fnInputstring);
- FreeFBuilder;
- Installed := False;
- end;
-
-
- END.
-