home *** CD-ROM | disk | FTP | other *** search
- unit UtilBox;
-
- interface
-
- uses
- WinTypes, WinProcs, Messages,
- SysUtils, Controls;
-
- function AddComma(S: string; MaxLen : Word): string;
- function WinExecAndWait(Path : Pchar; Visibility : word) : word;
- procedure YieldToOthers;
- function StrStripComma(S: PChar): PChar;
- function StrAddComma(S: PChar; MaxLen : Word): PChar;
- function PathToExe: string;
- procedure Center(var Child: TWinControl; Parent: TWinControl);
- implementation
-
- uses
- StrBox;
-
- {----------------------------------------------------
- Name: AddComma function
- Declaration: AddComma(S: string; MaxLen : Word): string;
- Unit: UtilBox
- Code: S
- Date: 03/05/95
- Description: Add commas to monetary values or to plain
- integers. Turn $234567 into $234,567
- -----------------------------------------------------}
-
- function AddComma(S: string; MaxLen : Word): string;
- var
- OffSet: Word;
- MinLoc: Word;
- NewLen: Word;
- Value, Decimal: Integer;
- SaveDec: string;
- begin
- NewLen := Length(S);
- OffSet := NewLen;
- MinLoc := 4;
- if (S[1] = '-') or (S[1] = '$') then Inc(MinLoc);
- if (S[2] = '-') or (S[2] = '$') then Inc(MinLoc);
- Decimal := Pos('.', S);
- if Decimal <> 0 then begin
- Move(S[Decimal], SaveDec[1], Succ(NewLen - Decimal));
- SaveDec[0] := Chr(Succ(NewLen - Decimal));
- S[0] := Chr(Pred(Decimal));
- NewLen := Decimal;
- OffSet := NewLen;
- end else begin
- SaveDec := '';
- Inc(NewLen);
- Inc(OffSet);
- end;
-
- while (OffSet > MinLoc) and (NewLen < MaxLen) do begin
- Dec(OffSet, 3);
- Value := (NewLen - OffSet);
- Inc(NewLen);
- S[0] := Chr(Pred(NewLen));
- Move(S[OffSet], S[Succ(OffSet)], Value);
- S[OffSet] := ',';
- end;
-
- AddComma := S + SaveDec;
- end;
-
- { Center the child control in the Parent control. You may need
- to typecast the Child control as a TWinControl before you
- can make this call. }
- procedure Center(var Child: TWinControl; Parent: TWinControl);
- var
- R: TRect;
- begin
- TWinControl(Child).BoundsRect := TWinControl(Parent).ClientRect;
- Child.Width := Child.Width - 10;
- Child.Top := Child.Top + 5;
- Child.Height := Child.Height - 10;
- Child.Left := Child.Left + 5;
- end;
-
- function PathToExe: string;
- var
- S: string;
- begin
- S := ParamStr(0);
- Result := StripLastToken(S, '\') + '\';
- end;
-
- {----------------------------------------------------
- Name: WinExecAndWait function
- Declaration: WinExecAndWait(Path : Pchar; Visibility : word) : word;
- Unit: UtilBox
- Code: S
- Date: 02/05/95
- Description: Execute a Windows 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 YieldToOthers;
- var
- Msg : TMsg;
- begin
- while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
- if (Msg.Message = WM_QUIT) then begin
- Halt;
- end;
- TranslateMessage(Msg);
- DispatchMessage(Msg);
- end;
- end;
-
- { Needs more testing }
- function StrAddComma(S: PChar; MaxLen : Word): PChar;
- var
- OffSet: Word;
- MinLoc: Word;
- NewLen: Word;
- begin
- NewLen := StrLen(S);
- OffSet := NewLen;
- MinLoc := 3;
- if S[1] = '-' then Inc(MinLoc);
- while (OffSet > MinLoc) and (NewLen < MaxLen) do begin
- Dec(OffSet, 3);
- StrMove(S + Succ(OffSet), S + OffSet, Succ(NewLen - OffSet));
- S[OffSet] := ',';
- Inc(NewLen);
- end;
- StrAddComma := S;
- end;
-
- { Needs more testing }
- function StrStripComma(S: PChar): PChar;
- var
- P: PChar;
- Len: Word;
- begin
- StrStripComma := S;
- Len := StrLen(S);
- P := StrScan(S, ',');;
- while P <> nil do begin
- StrMove(P, P+1, Len - (P-S));
- Dec(Len);
- P := StrScan(P, ',');
- end;
- end;
-
-
- end.
-
-