{----------------------------------------------------------------------------- ---> Project DelphiWorks <--- Version 1.4.1 ----------------------------------------------------------------------------- Unit: dwConvert.pas Description: Misc. conversion functions Author: Codehunter Works Release: 1.4.1 State: Unstable Date: 16.08.2004 Created: 14.12.2002 Last mod.: 14.02.2005 History: 12.04.2005, 14:40:09 - added dwRectToPoint 14.04.2005, 18:40:27 - added dwPointToStr 14.04.2005, 19:09:01 - added dwStrToPoint 14.04.2005, 19:15:19 - added dwStrToRect 14.04.2005, 19:24:37 - added dwRectToStr 14.04.2005, 19:42:22 - added dwRegColorToColor 20.06.2005, 15:11:25 - added dwFieldTypeToStr 11.01.2006, 20:50:41 - added dwImageFileFormatToStr 12.01.2006, 10:42:36 - added dwDimensionToStr 12.01.2006, 10:46:45 - added dwStrToDimension -----------------------------------------------------------------------------} unit dwConvert; interface uses dwTypes, Classes, Controls, Forms, Graphics, Windows, Db; function dwAlignToStr(Align: TAlign): String; function dwAnchorsToStr(Anchors: TAnchors): String; function dwAnsiToAscii(const AnsiStr: String): String; function dwAsciiToAnsi(const AsciiStr: String): String; function dwBiDiModeToStr(BiDiMode: TBiDiMode): String; function dwBinToHex(a: PChar): String; function dwBoolToByte(const ABool: Boolean): Byte; function dwBoolToStr(Bool: Boolean): String; function dwBorderIconsToStr(BorderIcons: TBorderIcons): String; function dwBorderStyleToStr(BorderStyle: TFormBorderStyle): String; function dwByteToBool(AByte: Byte): Boolean; function dwColorToHTMLColor(const Color: TColor): String; function dwColorToRegColor(const Color: TColor): String; function dwComPortToStr(const COMPort: TDWComPort): String; function dwConstraintsToStr(Constraints: TSizeConstraints): String; function dwControlScrollBarToStr(ControlScrollBar: TControlScrollBar): String; function dwDecToRoman(iDecimal: LongInt): String; function dwDefaultMonitorToStr(DefaultMonitor: TDefaultMonitor): String; function dwDimensionToStr(ADimension: TDWDimension): String; function dwDragKindToStr(DragKind: TDragKind): String; function dwDragModeToStr(DragMode: TDragMode): String; function dwFieldTypeToStr(AFieldType: TFieldType): String; function dwFontPitchToStr(FontPitch: TFontPitch): String; function dwFontStyleToStr(FontStyle: TFontStyles): String; function dwFontToStr(Font: TFont): String; function dwFormatBitDepth(const BitDepth: Integer): String; function dwFormatFrequency(const Frequency: Integer): String; function dwFormatScreenMode(const ScreenMode: TDWScreenMode): String; function dwFormStyleToStr(FormStyle: TFormStyle): String; function dwFreeNotationToFreeNotation(const Value, SrcNotationConfig, DstNotationConfig: String): String; function dwFreeNotationToInt(const Value, NotationConfig: String): Integer; function dwHexToBin(a: String): PChar; function dwHexToInt(HexStr: String): Integer; function dwHKEYToStr(const KEY: HKEY): String; function dwHTMLColorToTColor(const HTMLColor: String): TColor; function dwImageFileFormatToStr(const Value: TDWImageFileFormat): String; function dwIntToFreeNotation(const Value: Integer; const NotationConfig: String): String; function dwListToStr(List: TStrings; Delimeter: String): String; function dwPointToStr(const APoint: TPoint): String; function dwPositionToStr(Position: TPosition): String; function dwPrintScaleToStr(PrintScale: TPrintScale): String; function dwRect(ALeft, ATop, AHeight, AWidth: Integer): TRect; overload; function dwRect(ALeft, ATop, ARight, ABottom: DWord): TRect; overload; function dwRectToPoint(Rect: TRect; RectCorner: TDWRectCorner): TPoint; function dwRectToStr(const ARect: TRect): String; function dwRegColorToColor(const ARegColor: String): TColor; function dwRegColorToStr(const RegColor: String): String; function dwRomanToDec(const Roman: String): LongInt; function dwScrollBarStyleToStr(ScrollBarStyle: TScrollBarStyle): String; function dwSpecialFolderToCSIDL(const SpecialFolder: TDWSpecialFolder): Word; function dwStrToAlign(Align: String): TAlign; function dwStrToAnchors(Anchors: String): TAnchors; function dwStrToBiDiMode(BiDiMode: String): TBiDiMode; function dwStrToBool(Bool: String): Boolean; function dwStrToBorderIcons(BorderIcons: String): TBorderIcons; function dwStrToBorderStyle(BorderStyle: String): TFormBorderStyle; function dwStrToComPort(const Str: String): TDWComPort; function dwStrToConstraints(Constraints: String): TSizeConstraints; function dwStrToControlScrollBar(ControlScrollBar: String): TControlScrollBar; function dwStrToDefaultMonitor(DefaultMonitor: String): TDefaultMonitor; function dwStrToDimension(ADimension: String): TDWDimension; function dwStrToDragKind(DragKind: String): TDragKind; function dwStrToDragMode(DragMode: String): TDragMode; function dwStrToFontPitch(FontPitch: String): TFontPitch; function dwStrToFontStyle(FontStyle: String): TFontStyles; function dwStrToFont(Font: String): TFont; function dwStrToFormStyle(FormStyle: String): TFormStyle; function dwStrToHKEY(const KEY: String): HKEY; function dwStrToPoint(APointStr: String): TPoint; function dwStrToPosition(Position: String): TPosition; function dwStrToPrintScale(PrintScale: String): TPrintScale; function dwStrToRect(ARectStr: String): TRect; function dwStrToScrollBarStyle(ScrollBarStyle: String): TScrollBarStyle; function dwStrToWindowState(WindowState: String): TWindowState; function dwWindowStateToStr(WindowState: TWindowState): String; function dwVersionBlockToStr(const VersionBlock: TDWVersionBlock): String; procedure dwStrToList(Str, Delimeter: String; List: TStrings); implementation uses dwConsts, dwMathematics, dwStrings, dwLanguage, SysUtils; function dwAlignToStr(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 dwAnchorsToStr(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:= dwListToStr(TempList, '|'); TempList.Free; end; function dwAnsiToAscii(const AnsiStr: String): String; var AsciiStr: string; begin SetLength(AsciiStr, Length(AnsiStr)); if Length(AnsiStr) > 0 then CharToOem(PChar(AnsiStr), PChar(AsciiStr)); dwAnsiToAscii:= AsciiStr; end; function dwAsciiToAnsi(const AsciiStr: String): String; var AnsiStr: string; begin SetLength(AnsiStr, Length(AsciiStr)); if Length(AsciiStr) > 0 then OemToChar(PChar(AsciiStr), PChar(AnsiStr)); dwAsciiToAnsi:= AnsiStr; end; function dwBiDiModeToStr(BiDiMode: TBiDiMode): String; begin case BiDiMode of bdLeftToRight: result:= 'bdLeftToRight'; bdRightToLeft: result:= 'bdRightToLeft'; bdRightToLeftNoAlign: result:= 'bdRightToLeftNoAlign'; bdRightToLeftReadingOnly: result:= 'bdRightToLeftReadingOnly'; end; end; function dwBinToHex(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; function dwBoolToByte(const ABool: Boolean): Byte; begin if ABool then result:= 1 else result:= 0; end; function dwBoolToStr(Bool: Boolean): String; begin if Bool then result:= '1' else result:= '0'; end; function dwBorderIconsToStr(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:= dwListToStr(TempList, '|'); TempList.Free; end; function dwBorderStyleToStr(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 dwByteToBool(AByte: Byte): Boolean; begin result:= (AByte > 0); end; function dwColorToHTMLColor(const Color: TColor): String; var iR, iG, iB: Byte; begin iR:= GetRValue(Color); iG:= GetGValue(Color); iB:= GetBValue(Color); result:= Format('#%.2x%.2x%.2x', [iR, iG, iB]); end; function dwColorToRegColor(const Color: TColor): String; var clStr, sR, sG, sB: String; const spc: Char = ' '; dlr: Char = '$'; begin clStr:= IntToHex(Color, 6); sR:= dwStrRight(clStr, 2); sG:= dwStrMid(clStr, 3, 2); sB:= dwStrMid(clStr, 2, 2); sR:= IntToStr(StrToInt(dlr + sR)); sG:= IntToStr(StrToInt(dlr + sG)); sB:= IntToStr(StrToInt(dlr + sB)); result:= sR + spc + sG + spc + sB; end; function dwComPortToStr(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 dwConstraintsToStr(Constraints: TSizeConstraints): String; begin with Constraints do result:= IntToStr(MaxHeight) + '|' + IntToStr(MaxWidth) + '|' + IntToStr(MinHeight) + '|' + IntToStr(MinWidth); end; function dwControlScrollBarToStr(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(dwBoolToStr(ParentColor)); TempList.Add(IntToStr(Position)); TempList.Add(IntToStr(Range)); TempList.Add(IntToStr(Size)); TempList.Add(dwBoolToStr(Smooth)); TempList.Add(dwScrollBarStyleToStr(Style)); TempList.Add(IntToStr(ThumbSize)); TempList.Add(dwBoolToStr(Tracking)); TempList.Add(dwBoolToStr(Visible)); end; result:= dwListToStr(TempList, '|'); TempList.Free; end; function dwDecToRoman(iDecimal: LongInt): String; const aRomans: array [ 1..13 ] of String = ( 'I', 'IV', 'V', 'IX', 'X', 'XL','L', 'XC', 'C', 'CD', 'D', 'CM', 'M' ); aArabics: array [ 1..13 ] of Integer = ( 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 ); var I: Integer; begin for I := 13 downto 1 do begin while (iDecimal >= aArabics[I]) do begin iDecimal := iDecimal - aArabics[I]; result := result + aRomans[I]; end; end; end; function dwDefaultMonitorToStr(DefaultMonitor: TDefaultMonitor): String; begin result:= 'dmPrimary'; case DefaultMonitor of dmDesktop: result:= 'dmDesktop'; dmPrimary: result:= 'dmPrimary'; dmMainForm: result:= 'dmMainForm'; dmActiveForm: result:= 'dmActiveForm'; end; end; function dwDimensionToStr(ADimension: TDWDimension): String; begin result:= IntTostr(ADimension.Width) + 'x' + IntTostr(ADimension.Height); end; function dwDragKindToStr(DragKind: TDragKind): String; begin if DragKind = dkDrag then result:= 'dkDrag' else result:= 'dkDock'; end; function dwFreeNotationToFreeNotation(const Value, SrcNotationConfig, DstNotationConfig: String): String; begin result:= dwIntToFreeNotation(dwFreeNotationToInt( Value, SrcNotationConfig), DstNotationConfig); end; function dwFreeNotationToInt(const Value, NotationConfig: String): Integer; var iBase, iPot, iVal, iValue, I: Integer; sValue: String; begin iValue:= 0; sValue:= dwReverseStr(Value); iBase:= Length(NotationConfig); for I:= 0 to Length(sValue) - 1 do begin iVal:= Pos(sValue[I+1], NotationConfig) - 1; iPot:= dwExpon(iBase, I); iValue:= iValue + (iVal*(iPot)); end; result:= iValue; end; function dwHexToBin(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 dwHexToInt(HexStr: String): Integer; begin result:= StrToInt('$' + HexStr); end; function dwImageFileFormatToStr(const Value: TDWImageFileFormat): String; begin result:= ''; case Value of dwimfBMP: result:= 'BMP'; dwimfGIF: result:= 'GIF'; dwimfJPG: result:= 'JPG'; dwimfPNG: result:= 'PNG'; end; end; function dwIntToFreeNotation(const Value: Integer; const NotationConfig: String): String; var iBase, iDiv, iMod, iValue: Integer; begin result:= ''; iDiv:= -1; iValue:= Value; iBase:= Length(NotationConfig); while iDiv <> 0 do begin iMod:= iValue mod iBase; iDiv:= iValue div iBase; result:= result + NotationConfig[iMod+1]; iValue:= iDiv; end; result:= dwReverseStr(result); end; function dwHKEYToStr(const KEY: HKEY): String; begin case KEY of HKEY_CLASSES_ROOT: result:= 'HKEY_CLASSES_ROOT'; HKEY_CURRENT_USER: result:= 'HKEY_CURRENT_USER'; HKEY_LOCAL_MACHINE: result:= 'HKEY_LOCAL_MACHINE'; HKEY_USERS: result:= 'HKEY_USERS'; HKEY_PERFORMANCE_DATA: result:= 'HKEY_PERFORMANCE_DATA'; HKEY_CURRENT_CONFIG: result:= 'HKEY_CURRENT_CONFIG'; HKEY_DYN_DATA: result:= 'HKEY_DYN_DATA'; else result:= 'HKEY_LOCAL_MACHINE'; end; end; function dwHTMLColorToTColor(const HTMLColor: String): TColor; var sR, sG, sB, sHTMLColor: String; begin result:= clNone; sHTMLColor:= HTMLColor; if (sHTMLColor[1] = '#') then Delete(sHTMLColor, 1, 1); sHTMLColor:= Trim(sHTMLColor); if Length(sHTMLColor) <> 6 then exit; if not dwValidateValueForFreeNotation(sHTMLColor, DW_NOTATION_HEX) then exit; sR:= sHTMLColor[1] + sHTMLColor[2]; sG:= sHTMLColor[3] + sHTMLColor[4]; sB:= sHTMLColor[5] + sHTMLColor[6]; result:= StringToColor('$00' + sB + sG + sR); end; function dwListToStr(List: TStrings; 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, (Length(TempStr)-Length(Delimeter)+1), Length(Delimeter)); result:= TempStr; end; function dwPointToStr(const APoint: TPoint): String; begin result:= IntToStr(APoint.X) + ',' + IntToStr(APoint.Y); end; function dwPositionToStr(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 dwPrintScaleToStr(PrintScale: TPrintScale): String; begin result:= 'poProportional'; case PrintScale of poNone: result:= 'poNone'; poProportional: result:= 'poProportional'; poPrintToFit: result:= 'poPrintToFit'; end; end; function dwRect(ALeft, ATop, AHeight, AWidth: Integer): TRect; begin with result do begin Left:= ALeft; Top:= ATop; Right:= AWidth - ALeft; Bottom:= AHeight - ATop; end; end; function dwRect(ALeft, ATop, ARight, ABottom: DWord): TRect; begin with result do begin Left:= ALeft; Top:= ATop; Right:= ARight; Bottom:= ABottom; end; end; function dwRectToPoint(Rect: TRect; RectCorner: TDWRectCorner): TPoint; begin with result do begin case RectCorner of dwrcTopLeft: begin result:= Rect.TopLeft; end; dwrcTopRight: begin x:= Rect.Right; y:= Rect.Top; end; dwrcBottomRight: begin result:= Rect.BottomRight; end; dwrcBottomLeft: begin x:= Rect.Left; y:= Rect.Bottom; end; end; end; end; function dwRectToStr(const ARect: TRect): String; begin result:= IntToStr(ARect.Left) + ',' + IntToStr(ARect.Top) + ',' + IntToStr(ARect.Right) + ',' + IntToStr(ARect.Bottom); end; function dwRegColorToColor(const ARegColor: String): TColor; begin result:= StringToColor(dwRegColorToStr(ARegColor)); end; function dwRegColorToStr(const RegColor: String): String; var TempList: TStringList; sR, sG, sB: String; begin result:= ''; if dwCountCharInStr(RegColor, ' ') <> 2 then exit; if (Length(RegColor) > 11) or (Length(RegColor) < 5) then exit; TempList:= TStringList.Create; dwStrToList(RegColor, ' ', TempList); sR:= TempList[0]; sG:= TempList[1]; sB:= TempList[2]; result:= '$00' + IntToHex(StrToIntDef(sB, 0), 2) + IntToHex(StrToIntDef(sG, 0), 2) + IntToHex(StrToIntDef(sR, 0), 2); TempList.Free; end; function dwRomanToDec(const Roman: String): LongInt; const Numeros : Array[1..13] of Integer = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1); Romanos : Array[1..13] of String = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'); var i : Integer; Ro : String; Longitud : Integer; sRoman: String; begin Result := 0; sRoman := UpperCase(Roman); if dwValidateRoman(sRoman) then begin for i := 1 to 13 do begin Longitud := Length(Romanos[i]); Ro := Copy(sRoman, 1, Longitud); while ((Length(sRoman)>0) and (Ro = Romanos[i])) do begin sRoman:= Copy(sRoman, 1 + Longitud, Length(Roman) - 1); Result := Result + Numeros[i]; Ro := Copy(sRoman, 1, Longitud); end; end; end; end; function dwScrollBarStyleToStr(ScrollBarStyle: TScrollBarStyle): String; begin result:= 'ssRegular'; case ScrollBarStyle of ssRegular: result:= 'ssRegular'; ssFlat: result:= 'ssFlat'; ssHotTrack: result:= 'ssHotTrack'; end; end; function dwSpecialFolderToCSIDL(const SpecialFolder: TDWSpecialFolder): Word; begin case SpecialFolder of dwspfAdminTools: result:= $0030; dwspfAppData: result:= $001A; dwspfRecycleBin: result:= $000A; dwspfCommonAdminTools: result:= $002F; dwspfCommonAppData: result:= $0023; dwspfCommonDesktop: result:= $0019; dwspfCommonDocuments: result:= $002E; dwspfCommonFavorites: result:= $001F; dwspfCommonMusic: result:= $0035; dwspfCommonPictures: result:= $0036; dwspfCommonProgramFiles: result:= $002B; dwspfCommonPrograms: result:= $0017; dwspfCommonStartmenu: result:= $0016; dwspfCommonStartup: result:= $0018; dwspfCommonTemplates: result:= $002D; dwspfCommonVideo: result:= $0037; dwspfControls: result:= $0003; dwspfCookies: result:= $0021; dwspfDesktop: result:= $0000; dwspfDrives: result:= $0011; dwspfFavorites: result:= $0006; dwspfFonts: result:= $0014; dwspfHistory: result:= $0022; dwspfInternetCache: result:= $0020; dwspfLocalAppData: result:= $001C; dwspfMyMusic: result:= $000D; dwspfMyPictures: result:= $0027; dwspfMyVideo: result:= $000E; dwspfNetHood: result:= $0013; dwspfNetwork: result:= $0012; dwspfPersonal: result:= $0005; dwspfPrinters: result:= $0004; dwspfPrintHood: result:= $001B; dwspfProfile: result:= $0028; dwspfProgramFiles: result:= $0026; dwspfProgramFilesX86: result:= $002A; dwspfPrograms: result:= $0002; dwspfRecent: result:= $0008; dwspfSendTo: result:= $0009; dwspfStartMenu: result:= $000B; dwspfStartUp: result:= $0007; dwspfSystem: result:= $0025; dwspfSystemX86: result:= $0029; dwspfTemplates: result:= $0015; dwspfWindows: result:= $0024; else result:= $0026; {dwspfProgramFiles} end; end; function dwStrToAlign(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 dwStrToAnchors(Anchors: String): TAnchors; var TempList: TStringList; I: Integer; TempAnchors: TAnchors; begin TempList:= TStringlist.Create; dwStrToList(Anchors, '|', TempList); 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 dwStrToBiDiMode(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 dwStrToBool(Bool: String): Boolean; begin result:= (Bool = '1'); end; function dwStrToComPort(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 dwStrToConstraints(Constraints: String): TSizeConstraints; var TempList: TStringList; begin TempList:= TStringlist.Create; result:= TSizeConstraints.Create(Application.MainForm); dwStrToList(Constraints, '|', TempList); 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 dwStrToControlScrollBar(ControlScrollBar: String): TControlScrollBar; var TempList: TStringList; rslt: TControlScrollBar; begin TempList:= TStringlist.Create; dwStrToList(ControlScrollBar, '|', TempList); 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:= dwStrToBool(TempList[4]); // Position:= StrToIntDef(TempList[5], 0); // Range:= StrToIntDef(TempList[6], 0); Size:= StrToIntDef(TempList[7], 0); Smooth:= dwStrToBool(TempList[8]); Style:= dwStrToScrollBarStyle(TempList[9]); ThumbSize:= StrToIntDef(TempList[10], 0); Tracking:= dwStrToBool(TempList[11]); {Visible:= StrToBool(TempList[12]);//} end; result:= rslt; end; function dwStrToDefaultMonitor(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 dwStrToDimension(ADimension: String): TDWDimension; var iPos1: Integer; begin iPos1:= Pos('x', ADimension); result.Height:= StrToIntDef(dwStrClearToInteger(Copy(ADimension, iPos1 + 1, Length(ADimension))), 0); result.Width:= StrToIntDef(dwStrClearToInteger(Copy(ADimension, 1, iPos1 - 1)), 0); end; function dwStrToDragKind(DragKind: String): TDragKind; begin if DragKind = 'dkDrag' then result:= dkDrag else result:= dkDock; end; function dwDragModeToStr(DragMode: TDragMode): String; begin if DragMode = dmManual then result:= 'dmManual' else result:= 'dmAutomatic'; end; function dwFieldTypeToStr(AFieldType: TFieldType): String; begin case AFieldType of ftADT: result:= 'ftADT'; ftArray: result:= 'ftArray'; ftAutoInc: result:= 'ftAutoInc'; ftBCD: result:= 'ftBCD'; ftBlob: result:= 'ftBlob'; ftBoolean: result:= 'ftBoolean'; ftBytes: result:= 'ftBytes'; ftCurrency: result:= 'ftCurrency'; ftCursor: result:= 'ftCursor'; ftDataSet: result:= 'ftDataSet'; ftDate: result:= 'ftDate'; ftDateTime: result:= 'ftDateTime'; ftDBaseOle: result:= 'ftDBaseOle'; ftFixedChar: result:= 'ftFixedChar'; ftFloat: result:= 'ftFloat'; ftFmtMemo: result:= 'ftFmtMemo'; ftGraphic: result:= 'ftGraphic'; ftGuid: result:= 'ftGuid'; ftIDispatch: result:= 'ftIDispatch'; ftInteger: result:= 'ftInteger'; ftInterface: result:= 'ftInterface'; ftLargeint: result:= 'ftLargeint'; ftMemo: result:= 'ftMemo'; ftOraBlob: result:= 'ftOraBlob'; ftOraClob: result:= 'ftOraClob'; ftParadoxOle: result:= 'ftParadoxOle'; ftReference: result:= 'ftReference'; ftSmallint: result:= 'ftSmallint'; ftString: result:= 'ftString'; ftTime: result:= 'ftTime'; ftTypedBinary: result:= 'ftTypedBinary'; ftUnknown: result:= 'ftUnknown'; ftVarBytes: result:= 'ftVarBytes'; ftVariant: result:= 'ftVariant'; ftWideString: result:= 'ftWideString'; ftWord: result:= 'ftWord'; end; end; function dwFontPitchToStr(FontPitch: TFontPitch): String; begin result:= 'fpDefault'; case FontPitch of fpDefault: result:= 'fpDefault'; fpFixed: result:= 'fpFixed'; fpVariable: result:= 'fpVariable'; end; end; function dwFontStyleToStr(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:= dwListToStr(TempList, '~'); TempList.Free; end; function dwFontToStr(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(dwFontPitchToStr(Font.Pitch)); TempList.Add(IntToStr(Font.Size)); TempList.Add(dwFontStyleToStr(Font.Style)); result:= dwListToStr(TempList, '|'); TempList.Free; end; function dwFormatBitDepth(const BitDepth: Integer): String; begin case BitDepth of 4: result:= '16 ' + DWLNG_BitDepth0; 8: result:= '256 ' + DWLNG_BitDepth0; 16: result:= DWLNG_BitDepth1 + ' (16-' + DWLNG_BitDepth3 + ')'; 24: result:= DWLNG_BitDepth2 + ' (24-' + DWLNG_BitDepth3 + ')'; 32: result:= DWLNG_BitDepth2 + ' (32-' + DWLNG_BitDepth3 + ')'; else result:= IntToStr(BitDepth) + '-' + DWLNG_BitDepth3; end; end; function dwFormatFrequency(const Frequency: Integer): String; begin case Frequency of 1: result:= DWLNG_BitDepth5; else result:= IntToStr(Frequency) + ' ' + DWLNG_BitDepth4; end; end; function dwFormatScreenMode(const ScreenMode: TDWScreenMode): String; begin with ScreenMode do begin result:= IntToStr(XResolution) + ' ' + DWLNG_BitDepth6 + ' ' + IntToStr(YResolution) + DWLNG_BitDepth7 + ', ' + dwFormatBitDepth(BitDepth) + ', ' + dwFormatFrequency(Frequency); end; end; function dwFormStyleToStr(FormStyle: TFormStyle): String; begin result:= 'fsNormal'; case FormStyle of fsNormal: result:= 'fsNormal'; fsMDIChild: result:= 'fsMDIChild'; fsMDIForm: result:= 'fsMDIForm'; fsStayOnTop: result:= 'fsStayOnTop'; end; end; function dwStrToBorderIcons(BorderIcons: String): TBorderIcons; var TempList: TStringList; I: Integer; begin TempList:= TStringlist.Create; dwStrToList(BorderIcons, '|', TempList); 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 dwStrToBorderStyle(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 dwStrToDragMode(DragMode: String): TDragMode; begin if DragMode = 'dmManual' then result:= dmManual else result:= dmAutomatic; end; function dwStrToFontPitch(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 dwStrToFontStyle(FontStyle: String): TFontStyles; var TempList: TStringList; I: Integer; begin TempList:= TStringlist.Create; dwStrToList(FontStyle, '~', TempList); 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 dwStrToFormStyle(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 dwStrToFont(Font: String): TFont; var TempList: TStringList; bFont: TFont; begin TempList:= TStringlist.Create; dwStrToList(Font, '|', TempList); 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:= dwStrToFontPitch(TempList[4]); bFont.Size:= StrToIntDef(TempList[5], 8); bFont.Style:= dwStrToFontStyle(TempList[6]); TempList.Free; result:= bFont; end; function dwStrToHKEY(const KEY: String): HKEY; begin if KEY = 'HKEY_CLASSES_ROOT' then result:= HKEY_CLASSES_ROOT else if KEY = 'HKEY_CURRENT_USER' then result:= HKEY_CURRENT_USER else if KEY = 'HKEY_LOCAL_MACHINE' then result:= HKEY_LOCAL_MACHINE else if KEY = 'HKEY_USERS' then result:= HKEY_USERS else if KEY = 'HKEY_PERFORMANCE_DATA' then result:= HKEY_PERFORMANCE_DATA else if KEY = 'HKEY_CURRENT_CONFIG' then result:= HKEY_CURRENT_CONFIG else if KEY = 'HKEY_DYN_DATA' then result:= HKEY_DYN_DATA else result:= HKEY_LOCAL_MACHINE; end; procedure dwStrToList(Str, Delimeter: String; List: TStrings); var I, iPos1, iPos2, DelimCount, StringLen: Integer; begin List.Clear; // if not Assigned(List) then List:= TStringList.Create; DelimCount:= dwStringCountInStr(Delimeter, Str); if DelimCount < 1 then begin List.Add(Str); exit; end; StringLen:= StrLen(PChar(Str)); if Pos(Delimeter, Str) = 0 then exit else begin List.Add(dwStrLeft(Str, Pos(Delimeter, Str) - 1)); for I:= 0 to dwStringCountInStr(Delimeter, Str) - 2 do begin iPos1:= dwSubPositionByIndex(Str, Delimeter, I+1); iPos2:= dwSubPositionByIndex(Str, Delimeter, I+2); List.Add(dwStrMid(Str, iPos1 + 1, iPos2 - iPos1 - 1)); end; end; List.Add(dwStrPart(Str, dwSubPositionByIndex(Str, Delimeter, DelimCount)+1, StringLen+1)); end; function dwStrToPoint(APointStr: String): TPoint; var SL: TStringList; begin SL:= TStringList.Create; dwStrToList(APointStr, ',', SL); if SL.Count = 2 then begin result.X:= StrToIntDef(SL[0], 0); result.Y:= StrToIntDef(SL[1], 0); end else begin result.X:= 0; result.Y:= 0; end; SL.Free; end; function dwStrToPosition(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 dwStrToPrintScale(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 dwStrToRect(ARectStr: String): TRect; var SL: TStringList; begin SL:= TStringList.Create; dwStrToList(ARectStr, ',', SL); if SL.Count = 4 then begin result.Left:= StrToIntDef(SL[0], 0); result.Top:= StrToIntDef(SL[1], 0); result.Right:= StrToIntDef(SL[2], 0); result.Bottom:= StrToIntDef(SL[3], 0); end else begin result.Left:= 0; result.Top:= 0; result.Right:= 0; result.Bottom:= 0; end; SL.Free; end; function dwStrToScrollBarStyle(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 dwStrToWindowState(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 dwVersionBlockToStr(const VersionBlock: TDWVersionBlock): String; begin result:= IntToStr(VersionBlock.dwVersionMajor) + '.' + IntToStr(VersionBlock.dwVersionMinor); end; function dwWindowStateToStr(WindowState: TWindowState): String; begin result:= 'wsNormal'; case WindowState of wsNormal: result:= 'wsNormal'; wsMinimized: result:= 'wsMinimized'; wsMaximized: result:= 'wsMaximized'; end; end; end.