home *** CD-ROM | disk | FTP | other *** search
- (*-------------------------------StringWorks.pas--------------------------
- V1.0.242 - 08.07.2002 current release
- ------------------------------------------------------------------------*)
- unit StringWorks;
-
- interface
-
- uses Classes, Controls, Graphics, Forms, Dialogs, SysUtils, SystemWorks;
-
- function StrIsInteger(Str: String): Boolean;
- function StrClearToInteger(Str: String): String;
- function MasterPath: String;
- function CodeString(Strng, Code : String) : String;
- function CodeStringDelim(Str, Password: String; Delimiter: Char): String;
- function DecodeStringDelim(Str: String; Delimiter: Char): String;
- function StringLen(Str: String): Integer;
- function StringCountInStr(SubStr, Str: String): Integer;
- //function StringToColor(Str: String): TColor;
- function SubPositionByIndex(Str, SubStr: String; Index: Integer): Integer;
- function StrToList(Str, Delimeter: String): TStringList;
- function ListToStr(List: TStringList; Delimeter: String): String;
- function StrLeft(Str: String; Count: Integer): String;
- function StrMid(Str: String; Start, Count: Integer): String;
- function StrRight(Str: String; Count: Integer): String;
- function StrPart(Str: String; Start, Stop: Integer): String;
- procedure ShowInteger(Int: Integer);
- function BoolToStr(Bool: Boolean): String;
- function StrToBool(Bool: String): Boolean;
- function AlignToStr(Align: TAlign): String;
- function StrToAlign(Align: String): TAlign;
- function AnchorsToStr(Anchors: TAnchors): String;
- function StrToAnchors(Anchors: String): TAnchors;
- function BiDiModeToStr(BiDiMode: TBiDiMode): String;
- function StrToBiDiMode(BiDiMode: String): TBiDiMode;
- function BorderIconsToStr(BorderIcons: TBorderIcons): String;
- function StrToBorderIcons(BorderIcons: String): TBorderIcons;
- function BorderStyleToStr(BorderStyle: TFormBorderStyle): String;
- function StrToBorderStyle(BorderStyle: String): TFormBorderStyle;
- function ConstraintsToStr(Constraints: TSizeConstraints): String;
- function StrToConstraints(Constraints: String): TSizeConstraints;
- function DefaultMonitorToStr(DefaultMonitor: TDefaultMonitor): String;
- function StrToDefaultMonitor(DefaultMonitor: String): TDefaultMonitor;
- function DragKindToStr(DragKind: TDragKind): String;
- function StrToDragKind(DragKind: String): TDragKind;
- function DragModeToStr(DragMode: TDragMode): String;
- function StrToDragMode(DragMode: String): TDragMode;
- function FontPitchToStr(FontPitch: TFontPitch): String;
- function StrToFontPitch(FontPitch: String): TFontPitch;
- function FontStyleToStr(FontStyle: TFontStyles): String;
- function StrToFontStyle(FontStyle: String): TFontStyles;
- function FontToStr(Font: TFont): String;
- function StrToFont(Font: String): TFont;
- function FormStyleToStr(FormStyle: TFormStyle): String;
- function StrToFormStyle(FormStyle: String): TFormStyle;
- function ScrollBarStyleToStr(ScrollBarStyle: TScrollBarStyle): String;
- function StrToScrollBarStyle(ScrollBarStyle: String): TScrollBarStyle;
- function ControlScrollBarToStr(ControlScrollBar: TControlScrollBar): String;
- function StrToControlScrollBar(ControlScrollBar: String): TControlScrollBar;
- function PositionToStr(Position: TPosition): String;
- function StrToPosition(Position: String): TPosition;
- function PrintScaleToStr(PrintScale: TPrintScale): String;
- function StrToPrintScale(PrintScale: String): TPrintScale;
- function WindowStateToStr(WindowState: TWindowState): String;
- function StrToWindowState(WindowState: String): TWindowState;
-
- // Added rev. 1.0.235 / 11.12.2001
- function HexToBin(a: String): PChar;
- function BinToHex(a: PChar): String;
-
- // added rev. 1.0.236 / 27.12.2001
- procedure ReverseStringList(var List: TStringList);
-
- // added rev. 1.0.237 / 06.01.2002
- function ReplaceStr(OldStr, FillStr: String; ReplaceChar: Char; AlignRight: Boolean): String;
- function ReverseStr(const Str: String): String;
-
- // added rev. 1.0.238 / 10.01.2002
- function CountCharInStr(Str: String; Chr: Char): Integer;
-
- // added rev. 1.0.240 / 08.05.2002
- function AnsiToAscii(const AnsiStr: String): String;
- function AsciiToAnsi(const AsciiStr: String): String;
-
- // added rev. 1.0.241 / 20.05.2002
- function VersionBlockToStr(const VersionBlock: TDWVersionBlock): String;
-
- // added rev. 1.0.242 / 31.06.2002
- function ComPortToStr(const COMPort: TDWComPort): String;
- function StrToComPort(const Str: String): TDWComPort;
-
- // added rev. 1.0.242 / 02.07.2002
- function SmashStr(ValueA, ValueB: String): String;
-
- implementation
-
- uses Windows;
-
- function SmashStr(ValueA, ValueB: String): String;
- var
- i : Integer;
- strTemp : String;
- begin
- strTemp := ValueB;
- for i := 1 to Length(ValueB) do
- if Pos(ValueB[i], ValueA) = 0 then
- strTemp := StringReplace(strTemp, ValueB[i], '', [rfReplaceAll]);
- Result := strTemp;
- end;
-
- function ComPortToStr(const COMPort: TDWComPort): String;
- begin
- result:= '';
- case COMPort of
- dwcptCOM1: result:= 'COM1:';
- dwcptCOM2: result:= 'COM2:';
- dwcptCOM3: result:= 'COM3:';
- dwcptCOM4: result:= 'COM4:';
- dwcptCOM5: result:= 'COM5:';
- dwcptCOM6: result:= 'COM6:';
- dwcptCOM7: result:= 'COM7:';
- end;
- end;
-
- function StrToComPort(const Str: String): TDWComPort;
- begin
- result:= dwcptUnknown;
- if Pos('COM1:', Str)<>0 then result:= dwcptCOM1;
- if Pos('COM2:', Str)<>0 then result:= dwcptCOM2;
- if Pos('COM3:', Str)<>0 then result:= dwcptCOM3;
- if Pos('COM4:', Str)<>0 then result:= dwcptCOM4;
- if Pos('COM5:', Str)<>0 then result:= dwcptCOM5;
- if Pos('COM6:', Str)<>0 then result:= dwcptCOM6;
- if Pos('COM7:', Str)<>0 then result:= dwcptCOM7;
- end;
-
- function VersionBlockToStr(const VersionBlock: TDWVersionBlock): String;
- begin
- result:= IntToStr(VersionBlock.dwVersionMajor) + '.' +
- IntToStr(VersionBlock.dwVersionMinor);
- end;
-
- function AnsiToAscii(const AnsiStr: String): String;
- var AsciiStr: string;
- begin
- SetLength(AsciiStr, Length(AnsiStr));
- if Length(AnsiStr) > 0 then CharToOem(PChar(AnsiStr), PChar(AsciiStr));
- AnsiToAscii:= AsciiStr;
- end;
-
- function AsciiToAnsi(const AsciiStr: String): String;
- var AnsiStr: string;
- begin
- SetLength(AnsiStr, Length(AsciiStr));
- if Length(AsciiStr) > 0 then OemToChar(PChar(AsciiStr), PChar(AnsiStr));
- AsciiToAnsi:= AnsiStr;
- end;
-
- function StrIsInteger(Str: String): Boolean;
- begin
- result:= not (StrToIntDef(Str, -2147483647)=-2147483647);
- end;
-
- function StrClearToInteger(Str: String): String;
- var i: integer;
- begin
- Result := Str;
- for i := Length(Result) downto 1 do
- if not (Result[i] in ['0'..'9']) then
- Delete(Result, i, 1);
- end;
-
- function MasterPath: String;
- begin
- result:= UpperCase(IncludeTrailingBackslash(ExtractFilePath(Application.Exename)));
- end;
-
- function CodeString(Strng, Code : String) : String;
- var
- i : byte;
- h : string;
- j : byte;
- begin
- Code:= ReverseStr(Code);
- i := 1;
- h := '';
- j := 1;
- while (i <= length(strng)) do
- begin
- h := h + chr(ord(strng[i]) xor ord(code[j]));
- inc(i);
- if j = length(code) then j := 1 else inc(j);
- end;
- result:= h;
- end;
-
- function CodeStringDelim(Str, Password: String; Delimiter: Char): String;
- begin
- Password:= ReverseStr(Password);
- result:= CodeString(Str, Password) + Delimiter + Password;
- end;
-
- function DecodeStringDelim(Str: String; Delimiter: Char): String;
- var
- TL: TStringList;
- CodedStr, Pwd: String;
- begin
- TL:= TStringList.Create;
- TL.Assign(StrToList(Str, Delimiter));
- CodedStr:= TL[0];
- Pwd:= TL[1];
- TL.Free;
- // Pwd:= ReverseStr(Pwd);
- result:= CodeString(CodedStr, Pwd);
- end;
-
- function StringLen(Str: String): Integer;
- begin
- result:= StrLen(PChar(Str));
- end;
-
- function StringCountInStr(SubStr, Str: String): Integer;
- var
- StrLn, SubLn, I: Integer;
- TempStr: String;
- begin
- StrLn:= StrLen(PChar(Str));
- SubLn:= StrLen(PChar(SubStr));
- TempStr:= Str;
- result:= 0;
- for I:= 0 to StrLn - 1 do begin
- TempStr:= Copy(Str, I + 1, SubLn);
- if TempStr = SubStr then Inc(result);
- end;
- end;
-
- {function StringToColor(Str: String): TColor;
- function GetHexValue(Input: Char): Byte;
- begin
- case UpCase(Input) of
- '0' : Result := 0;
- '1' : Result := 1;
- '2' : Result := 2;
- '3' : Result := 3;
- '4' : Result := 4;
- '5' : Result := 5;
- '6' : Result := 6;
- '7' : Result := 7;
- '8' : Result := 8;
- '9' : Result := 9;
- 'A' : Result := 10;
- 'B' : Result := 11;
- 'C' : Result := 12;
- 'D' : Result := 13;
- 'E' : Result := 14;
- 'F' : Result := 15;
- end;
- end;
- var
- Bytes : Array[0..3] of Byte;
- begin
- Bytes[0] := GetHexValue(Str[2]) * 16 + GetHexValue(Str[3]);
- Bytes[1] := GetHexValue(Str[4]) * 16 + GetHexValue(Str[5]);
- Bytes[2] := GetHexValue(Str[6]) * 16 + GetHexValue(Str[7]);
- Bytes[3] := GetHexValue(Str[8]) * 16 + GetHexValue(Str[9]);
- result := Bytes[3] + Bytes[2] * 256 + Bytes[1] * 256 * 256 + Bytes[0] * 256 * 256 * 256;
- end; }
-
- function SubPositionByIndex(Str, SubStr: String; Index: Integer): Integer;
- var
- StrLn, SubLn, Lock, I: Integer;
- TempStr: String;
- begin
- StrLn:= StrLen(PChar(Str));
- SubLn:= StrLen(PChar(SubStr));
- result:= 0;
- Lock:= 0;
- for I:= 0 to StrLn - 1 do begin
- TempStr:= Copy(Str, I + 1, SubLn);
- if TempStr = SubStr then Inc(Lock);
- if Lock = Index then begin
- result:= I + 1;
- break;
- end;
- end;
- end;
-
- function StrToList(Str, Delimeter: String): TStringList;
- var
- I, iPos1, iPos2, DelimCount, StringLen: Integer;
- begin
- result:= TStringList.Create;
- DelimCount:= StringCountInStr(Delimeter, Str);
- if DelimCount < 1 then begin
- result.Add(Str);
- exit;
- end;
- StringLen:= StrLen(PChar(Str));
- if Pos(Delimeter, Str) = 0 then exit else begin
- result.Add(StrLeft(Str, Pos(Delimeter, Str) - 1));
- for I:= 0 to StringCountInStr(Delimeter, Str) - 2 do begin
- iPos1:= SubPositionByIndex(Str, Delimeter, I+1);
- iPos2:= SubPositionByIndex(Str, Delimeter, I+2);
- result.Add(StrMid(Str, iPos1 + 1, iPos2 - iPos1 - 1));
- end;
- end;
- result.Add(StrPart(Str, SubPositionByIndex(Str, Delimeter, DelimCount)+1,
- StringLen+1));
- end;
-
- function ListToStr(List: TStringList; Delimeter: String): String;
- var
- I: Integer;
- TempStr: String;
- begin
- for I:= 0 to List.Count - 1 do begin
- TempStr:= TempStr + List[I] + Delimeter;
- end;
- Delete(TempStr, (StringLen(TempStr)-StringLen(Delimeter)+1), StringLen(Delimeter));
- result:= TempStr;
- end;
-
- function StrLeft(Str: String; Count: Integer): String;
- begin
- result:= Copy(Str, 1, Count);
- end;
-
- function StrMid(Str: String; Start, Count: Integer): String;
- begin
- result:= Copy(Str, Start, Count);
- end;
-
- function StrRight(Str: String; Count: Integer): String;
- var StrLn: Integer;
- begin
- StrLn:= StrLen(PChar(Str));
- result:= Copy(Str, StrLn - (Count - 1), Count);
- end;
-
- function StrPart(Str: String; Start, Stop: Integer): String;
- //var StrLn: Integer;
- begin
- // StrLn:= StrLen(PChar(Str));
- result:= Copy(Str, Start, Stop - Start);
- end;
-
- procedure ShowInteger(Int: Integer);
- begin
- ShowMessage(IntToStr(Int));
- end;
-
- function BoolToStr(Bool: Boolean): String;
- begin
- if Bool then result:= '1' else result:= '0';
- end;
-
- function StrToBool(Bool: String): Boolean;
- begin
- result:= (Bool = '1');
- end;
-
- function AlignToStr(Align: TAlign): String;
- begin
- result:= 'alNone';
- case Align of
- alBottom: result:= 'alBottom';
- alClient: result:= 'alClient';
- alLeft: result:= 'alLeft';
- alRight: result:= 'alRight';
- alTop: result:= 'alTop';
- end;
- end;
-
- function StrToAlign(Align: String): TAlign;
- begin
- result:= alNone;
- if Align = 'alBottom' then result:= alBottom else
- if Align = 'alClient' then result:= alClient else
- if Align = 'alLeft' then result:= alLeft else
- if Align = 'alRight' then result:= alRight else
- if Align = 'alTop' then result:= alTop;
- end;
-
- function AnchorsToStr(Anchors: TAnchors): String;
- var TempList: TStringList;
- begin
- TempList:= TStringList.Create;
- if akLeft in Anchors then TempList.Add('akLeft');
- if akTop in Anchors then TempList.Add('akTop');
- if akRight in Anchors then TempList.Add('akRight');
- if akBottom in Anchors then TempList.Add('akBottom');
- result:= ListToStr(TempList, '|');
- TempList.Free;
- end;
-
- function StrToAnchors(Anchors: String): TAnchors;
- var
- TempList: TStringList;
- I: Integer;
- TempAnchors: TAnchors;
- begin
- TempList:= StrToList(Anchors, '|');
- for I:= 0 to TempList.Count - 1 do begin
- if TempList[I] = 'akLeft' then Include(TempAnchors, akLeft);
- if TempList[I] = 'akTop' then Include(TempAnchors, akTop);
- if TempList[I] = 'akRight' then Include(TempAnchors, akRight);
- if TempList[I] = 'akBottom' then Include(TempAnchors, akBottom);
- end;
- result:= TempAnchors;
- TempList.Free;
- end;
-
- function BiDiModeToStr(BiDiMode: TBiDiMode): String;
- begin
- case BiDiMode of
- bdLeftToRight: result:= 'bdLeftToRight';
- bdRightToLeft: result:= 'bdRightToLeft';
- bdRightToLeftNoAlign: result:= 'bdRightToLeftNoAlign';
- bdRightToLeftReadingOnly: result:= 'bdRightToLeftReadingOnly';
- end;
- end;
-
- function StrToBiDiMode(BiDiMode: String): TBiDiMode;
- begin
- result:= bdLeftToRight;
- if BiDiMode = 'bdLeftToRight' then result:= bdLeftToRight else
- if BiDiMode = 'bdRightToLeft' then result:= bdRightToLeft else
- if BiDiMode = 'bdRightToLeftNoAlign' then result:= bdRightToLeftNoAlign else
- if BiDiMode = 'bdRightToLeftReadingOnly' then result:= bdRightToLeftReadingOnly;
- end;
-
- function BorderIconsToStr(BorderIcons: TBorderIcons): String;
- var
- TempList: TStringList;
- begin
- TempList:= TStringList.Create;
- if biSystemMenu in BorderIcons then TempList.Add('biSystemMenu');
- if biMinimize in BorderIcons then TempList.Add('biMinimize');
- if biMaximize in BorderIcons then TempList.Add('biMaximize');
- if biHelp in BorderIcons then TempList.Add('biHelp');
- result:= ListToStr(TempList, '|');
- TempList.Free;
- end;
-
- function StrToBorderIcons(BorderIcons: String): TBorderIcons;
- var
- TempList: TStringList;
- I: Integer;
- begin
- TempList:= StrToList(BorderIcons, '|');
- for I:= 0 to TempList.Count -1 do begin
- if TempList[I] = 'biSystemMenu' then Include(result, biSystemMenu);
- if TempList[I] = 'biMinimize' then Include(result, biMinimize);
- if TempList[I] = 'biMaximize' then Include(result, biMaximize);
- if TempList[I] = 'biHelp' then Include(result, biHelp);
- end;
- TempList.Free;
- end;
-
- function BorderStyleToStr(BorderStyle: TFormBorderStyle): String;
- begin
- result:= 'bsSizeable';
- case BorderStyle of
- bsDialog: result:= 'bsDialog';
- bsNone: result:= 'bsNone';
- bsSingle: result:= 'bsSingle';
- bsSizeable: result:= 'bsSizeable';
- bsSizeToolWin: result:= 'bsSizeToolWin';
- bsToolWindow: result:= 'bsToolWindow';
- end;
- end;
-
- function StrToBorderStyle(BorderStyle: String): TFormBorderStyle;
- begin
- result:= bsSizeable;
- if BorderStyle = 'bsDialog' then result:= bsDialog;
- if BorderStyle = 'bsNone' then result:= bsNone;
- if BorderStyle = 'bsSingle' then result:= bsSingle;
- if BorderStyle = 'bsSizeable' then result:= bsSizeable;
- if BorderStyle = 'bsSizeToolWin' then result:= bsSizeToolWin;
- if BorderStyle = 'bsToolWindow' then result:= bsToolWindow;
- end;
-
- function ConstraintsToStr(Constraints: TSizeConstraints): String;
- begin
- with Constraints do
- result:= IntToStr(MaxHeight) + '|' +
- IntToStr(MaxWidth) + '|' +
- IntToStr(MinHeight) + '|' +
- IntToStr(MinWidth);
- end;
-
- function StrToConstraints(Constraints: String): TSizeConstraints;
- var
- TempList: TStringList;
- begin
- result:= TSizeConstraints.Create(Application.MainForm);
- TempList:= StrToList(Constraints, '|');
- result.MaxHeight:= StrToIntDef(TempList[0], 0);
- result.MaxWidth:= StrToIntDef(TempList[1], 0);
- result.MinHeight:= StrToIntDef(TempList[2], 0);
- result.MinWidth:= StrToIntDef(TempList[3], 0);
- TempList.Free;
- end;
-
- function DefaultMonitorToStr(DefaultMonitor: TDefaultMonitor): String;
- begin
- result:= 'dmPrimary';
- case DefaultMonitor of
- dmDesktop: result:= 'dmDesktop';
- dmPrimary: result:= 'dmPrimary';
- dmMainForm: result:= 'dmMainForm';
- dmActiveForm: result:= 'dmActiveForm';
- end;
- end;
-
- function StrToDefaultMonitor(DefaultMonitor: String): TDefaultMonitor;
- begin
- result:= dmPrimary;
- if DefaultMonitor = 'dmDesktop' then result:= dmDesktop else
- if DefaultMonitor = 'dmPrimary' then result:= dmPrimary else
- if DefaultMonitor = 'dmMainForm' then result:= dmMainForm else
- if DefaultMonitor = 'dmActiveForm' then result:= dmActiveForm;
- end;
-
- function DragKindToStr(DragKind: TDragKind): String;
- begin
- if DragKind = dkDrag then result:= 'dkDrag' else result:= 'dkDock';
- end;
-
- function StrToDragKind(DragKind: String): TDragKind;
- begin
- if DragKind = 'dkDrag' then result:= dkDrag else result:= dkDock;
- end;
-
- function DragModeToStr(DragMode: TDragMode): String;
- begin
- if DragMode = dmManual then result:= 'dmManual' else result:= 'dmAutomatic';
- end;
-
- function StrToDragMode(DragMode: String): TDragMode;
- begin
- if DragMode = 'dmManual' then result:= dmManual else result:= dmAutomatic;
- end;
-
- function FontPitchToStr(FontPitch: TFontPitch): String;
- begin
- result:= 'fpDefault';
- case FontPitch of
- fpDefault: result:= 'fpDefault';
- fpFixed: result:= 'fpFixed';
- fpVariable: result:= 'fpVariable';
- end;
- end;
-
- function StrToFontPitch(FontPitch: String): TFontPitch;
- begin
- result:= fpDefault;
- if FontPitch = 'fpDefault' then result:= fpDefault else
- if FontPitch = 'fpFixed' then result:= fpFixed else
- if FontPitch = 'fpVariable' then result:= fpVariable;
- end;
-
- function FontStyleToStr(FontStyle: TFontStyles): String;
- var
- TempList: TStringList;
- begin
- TempList:= TStringList.Create;
- if fsBold in FontStyle then TempList.Add('fsBold');
- if fsItalic in FontStyle then TempList.Add('fsItalic');
- if fsUnderline in FontStyle then TempList.Add('fsUnderline');
- if fsStrikeOut in FontStyle then TempList.Add('fsStrikeOut');
- if TempList.Count = 0 then TempList.Add('fsNone');
- result:= ListToStr(TempList, '~');
- TempList.Free;
- end;
-
- function StrToFontStyle(FontStyle: String): TFontStyles;
- var
- TempList: TStringList;
- I: Integer;
- begin
- TempList:= StrToList(FontStyle, '~');
- result:= [];
- for I:= 0 to TempList.Count - 1 do begin
- if TempList[I] = 'fsBold' then Include(result, fsBold) else
- if TempList[I] = 'fsItalic' then Include(result, fsItalic) else
- if TempList[I] = 'fsUnderline' then Include(result, fsUnderline) else
- if TempList[I] = 'fsStrikeOut' then Include(result, fsStrikeOut);
- end;
- TempList.Free;
- end;
-
- function FontToStr(Font: TFont): String;
- var
- TempList: TStringList;
- begin
- TempList:= TStringList.Create;
- TempList.Add(IntToStr(Int64(Font.Charset)));
- TempList.Add(ColorToString(Font.Color));
- TempList.Add(IntToStr(Font.Height));
- TempList.Add(Font.Name);
- TempList.Add(FontPitchToStr(Font.Pitch));
- TempList.Add(IntToStr(Font.Size));
- TempList.Add(FontStyleToStr(Font.Style));
- result:= ListToStr(TempList, '|');
- TempList.Free;
- end;
-
- function StrToFont(Font: String): TFont;
- var
- TempList: TStringList;
- bFont: TFont;
- begin
- TempList:= StrToList(Font, '|');
- bFont:= TFont.Create;
- bFont.Charset:= StrToIntDef(TempList[0], 1);
- bFont.Color:= StringToColor(TempList[1]);
- bFont.Height:= StrToIntDef(TempList[2], -11);
- bFont.Name:= TempList[3];
- bFont.Pitch:= StrToFontPitch(TempList[4]);
- bFont.Size:= StrToIntDef(TempList[5], 8);
- bFont.Style:= StrToFontStyle(TempList[6]);
- TempList.Free;
- result:= bFont;
- end;
-
- function FormStyleToStr(FormStyle: TFormStyle): String;
- begin
- result:= 'fsNormal';
- case FormStyle of
- fsNormal: result:= 'fsNormal';
- fsMDIChild: result:= 'fsMDIChild';
- fsMDIForm: result:= 'fsMDIForm';
- fsStayOnTop: result:= 'fsStayOnTop';
- end;
- end;
-
- function StrToFormStyle(FormStyle: String): TFormStyle;
- begin
- result:= fsNormal;
- if FormStyle = 'fsNormal' then result:= fsNormal else
- if FormStyle = 'fsMDIChild' then result:= fsMDIChild else
- if FormStyle = 'fsMDIForm' then result:= fsMDIForm else
- if FormStyle = 'fsStayOnTop' then result:= fsStayOnTop;
- end;
-
- function ScrollBarStyleToStr(ScrollBarStyle: TScrollBarStyle): String;
- begin
- result:= 'ssRegular';
- case ScrollBarStyle of
- ssRegular: result:= 'ssRegular';
- ssFlat: result:= 'ssFlat';
- ssHotTrack: result:= 'ssHotTrack';
- end;
- end;
-
- function StrToScrollBarStyle(ScrollBarStyle: String): TScrollBarStyle;
- begin
- result:= ssRegular;
- if ScrollBarStyle = 'ssRegular' then result:= ssRegular else
- if ScrollBarStyle = 'ssFlat' then result:= ssFlat else
- if ScrollBarStyle = 'ssHotTrack' then result:= ssHotTrack;
- end;
-
- function ControlScrollBarToStr(ControlScrollBar: TControlScrollBar): String;
- var
- TempList: TStringList;
- begin
- TempList:= TStringList.Create;
- with ControlScrollBar do begin
- TempList.Add(IntToStr(ButtonSize));
- TempList.Add(ColorToString(Color));
- TempList.Add(IntToStr(Increment));
- TempList.Add(IntToStr(Margin));
- TempList.Add(BoolToStr(ParentColor));
- TempList.Add(IntToStr(Position));
- TempList.Add(IntToStr(Range));
- TempList.Add(IntToStr(Size));
- TempList.Add(BoolToStr(Smooth));
- TempList.Add(ScrollBarStyleToStr(Style));
- TempList.Add(IntToStr(ThumbSize));
- TempList.Add(BoolToStr(Tracking));
- TempList.Add(BoolToStr(Visible));
- end;
- result:= ListToStr(TempList, '|');
- TempList.Free;
- end;
-
- function StrToControlScrollBar(ControlScrollBar: String): TControlScrollBar;
- var
- TempList: TStringList;
- rslt: TControlScrollBar;
- begin
- TempList:= StrToList(ControlScrollBar, '|');
- rslt:= TControlScrollBar.Create;
- with rslt do begin
- ButtonSize:= StrToIntDef(TempList[0], 0);
- // Color:= StringToColor(TempList[1]);
- Increment:= StrToIntDef(TempList[2], 8);
- Margin:= StrToIntDef(TempList[3], 0);
- ParentColor:= StrToBool(TempList[4]);
- // Position:= StrToIntDef(TempList[5], 0);
- // Range:= StrToIntDef(TempList[6], 0);
- Size:= StrToIntDef(TempList[7], 0);
- Smooth:= StrToBool(TempList[8]);
- Style:= StrToScrollBarStyle(TempList[9]);
- ThumbSize:= StrToIntDef(TempList[10], 0);
- Tracking:= StrToBool(TempList[11]);
- {Visible:= StrToBool(TempList[12]);//}
- end;
- result:= rslt;
- end;
-
- function PositionToStr(Position: TPosition): String;
- begin
- result:= 'poDesigned';
- case Position of
- poDesigned: result:= 'poDesigned';
- poDefault: result:= 'poDefault';
- poDefaultPosOnly: result:= 'poDefaultPosOnly';
- poDefaultSizeOnly: result:= 'poDefaultSizeOnly';
- poScreenCenter: result:= 'poScreenCenter';
- poDesktopCenter: result:= 'poDesktopCenter';
- poMainFormCenter: result:= 'poMainFormCenter';
- poOwnerFormCenter: result:= 'poOwnerFormCenter';
- end;
- end;
-
- function StrToPosition(Position: String): TPosition;
- begin
- result:= poDesigned;
- if Position = 'poDesigned' then result:= poDesigned else
- if Position = 'poDefault' then result:= poDesigned else
- if Position = 'poDefaultPosOnly' then result:= poDefaultPosOnly else
- if Position = 'poDefaultSizeOnly' then result:= poDefaultSizeOnly else
- if Position = 'poScreenCenter' then result:= poScreenCenter else
- if Position = 'poDesktopCenter' then result:= poDesktopCenter else
- if Position = 'poMainFormCenter' then result:= poMainFormCenter else
- if Position = 'poOwnerFormCenter' then result:= poOwnerFormCenter;
- end;
-
- function PrintScaleToStr(PrintScale: TPrintScale): String;
- begin
- result:= 'poProportional';
- case PrintScale of
- poNone: result:= 'poNone';
- poProportional: result:= 'poProportional';
- poPrintToFit: result:= 'poPrintToFit';
- end;
- end;
-
- function StrToPrintScale(PrintScale: String): TPrintScale;
- begin
- result:= poProportional;
- if PrintScale = 'poNone' then result:= poNone else
- if PrintScale = 'poProportional' then result:= poProportional else
- if PrintScale = 'poPrintToFit' then result:= poPrintToFit;
- end;
-
- function WindowStateToStr(WindowState: TWindowState): String;
- begin
- result:= 'wsNormal';
- case WindowState of
- wsNormal: result:= 'wsNormal';
- wsMinimized: result:= 'wsMinimized';
- wsMaximized: result:= 'wsMaximized';
- end;
- end;
-
- function StrToWindowState(WindowState: String): TWindowState;
- begin
- result:= wsNormal;
- if WindowState = 'wsNormal' then result:= wsNormal else
- if WindowState = 'wsMinimized' then result:= wsMinimized else
- if WindowState = 'wsMaximized' then result:= wsMaximized;
- end;
-
- function HexToBin(a: String): PChar;
- var
- i, j: Integer;
- s: String;
- p, r: PChar;
- const
- HexString: array[0..15] of Char = ('0', '1', '2', '3',
- '4', '5', '6', '7',
- '8', '9', 'A', 'B',
- 'C', 'D', 'E', 'F');
- BinString: array[0..15] of String = ('0000', '0001', '0010', '0011',
- '0100', '0101', '0110', '0111',
- '1000', '1001', '1010', '1011',
- '1100', '1101', '1110', '1111');
- begin
- s := '';
- r := StrAlloc(65000);
- p := StrAlloc(65000);
- StrPCopy(r, '');
- for i := 1 to Length(a) do
- s := s + IntToHex(Ord(a[i]), 2);
- for i := 1 to Length(s) do begin
- for j := 0 to 15 do begin
- if s[i] = HexString[j] then begin
- StrPCopy(p, '');
- StrPCopy(p, BinString[j]);
- StrCat(r, p);
- end;
- end;
- end;
- StrDispose(p);
- Result := StrAlloc(65000);
- StrCopy(Result, r);
- end;
-
- function BinToHex(a: PChar): String;
- var
- i, j: Integer;
- s: String;
- HexString: array[0..15] of Char;
- BinString: array[0..15] of String;
- begin
- HexString[0] := '0';
- HexString[1] := '1';
- HexString[2] := '2';
- HexString[3] := '3';
- HexString[4] := '4';
- HexString[5] := '5';
- HexString[6] := '6';
- HexString[7] := '7';
- HexString[8] := '8';
- HexString[9] := '9';
- HexString[10] := 'A';
- HexString[11] := 'B';
- HexString[12] := 'C';
- HexString[13] := 'D';
- HexString[14] := 'E';
- HexString[15] := 'F';
- BinString[0] := '0000';
- BinString[1] := '0001';
- BinString[2] := '0010';
- BinString[3] := '0011';
- BinString[4] := '0100';
- BinString[5] := '0101';
- BinString[6] := '0110';
- BinString[7] := '0111';
- BinString[8] := '1000';
- BinString[9] := '1001';
- BinString[10] := '1010';
- BinString[11] := '1011';
- BinString[12] := '1100';
- BinString[13] := '1101';
- BinString[14] := '1110';
- BinString[15] := '1111';
- s := '';
- Result := '';
- j := 0;
- while a[j] <> #0 do begin
- i := 0;
- s := '';
- while i < 4 do begin
- s := s + a[j];
- inc(i);
- inc(j);
- end;
- for i := 0 to 15 do begin
- if s = BinString[i] then begin
- Result := Result + HexString[i];
- end;
- end;
- end;
- end;
-
- procedure ReverseStringList(var List: TStringList);
- var
- TempList: TStringList;
- I: Integer;
- begin
- TempList:= TStringList.Create;
- for I:= List.Count - 1 downto 0 do begin
- TempList.Add(List[I]);
- end;
- List.Assign(TempList);
- TempList.Free;
- end;
-
- function ReplaceStr(OldStr, FillStr: String; ReplaceChar: Char; AlignRight: Boolean): String;
- var
- fcCount, I, J, K: Integer;
- begin
- if (StringLen(OldStr) < 1) then exit;
- result:= OldStr;
- if (StringLen(FillStr) < 1) then exit;
- fcCount:= StringCountInStr(ReplaceChar, OldStr);
- if fcCount < 1 then exit;
- if not AlignRight then begin
- K:= 0;
- for I:= 1 to StringLen(OldStr) do begin
- if OldStr[I] = ReplaceChar then begin
- inc(K);
- if not (K > StringLen(FillStr)) then OldStr[I]:= FillStr[K];
- end;
- end;
- end else begin
- FillStr:= ReverseStr(FillStr);
- K:= 0;
- for J:= StringLen(OldStr) downto 1 do begin
- if OldStr[J] = ReplaceChar then begin
- inc(K);
- if not (K > StringLen(FillStr)) then OldStr[J]:= FillStr[K];
- end;
- end;
- end;
- result:= OldStr;
- end;
-
- function ReverseStr(const Str: String): String;
- var
- I: Integer;
- begin
- result:= Str;
- if StringLen(Str) < 2 then exit;
- for I:= StringLen(Str) downto 1 do begin
- result[I]:= Str[(StringLen(Str) - I) + 1];
- end;
- end;
-
- function CountCharInStr(Str: String; Chr: Char): Integer;
- var
- I: Integer;
- begin
- result:= 0;
- for I:= 1 to StringLen(Str) do begin
- if Str[I] = Chr then Inc(result);
- end;
- end;
-
- end.
-
-