From: Peter T. <pe...@us...> - 2003-06-26 21:10:48
|
Update of /cvsroot/jvcl/dev/JVCL3/archive In directory sc8-pr-cvs1:/tmp/cvs-serv25713/JVCL3/archive Added Files: JvAutoSave.pas JvInterpreter_JvRegAuto.pas JvRegAuto.pas JvRegAutoEditorForm.dfm JvRegAutoEditorForm.pas Log Message: - Moved JvAutoSave and JvRegAuto units to \archive --- NEW FILE: JvAutoSave.pas --- {----------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: JvPropAutoSave.PAS, released on 2001-02-28. The Initial Developer of the Original Code is Sébastien Buysse [sb...@bu...] Portions created by Sébastien Buysse are Copyright (C) 2001 Sébastien Buysse. All Rights Reserved. Contributor(s): Michael Beck [mb...@bi...]. Last Modified: 2000-02-28 You may retrieve the latest version of this file at the Project JEDI's JVCL home page, located at http://jvcl.sourceforge.net Known Issues: -----------------------------------------------------------------------------} {$I JVCL.INC} unit JvAutoSave; interface uses SysUtils, Classes, Registry; type TJvRegAutoSave = class(TPersistent) private FPath: string; FKey: string; published property Key: string read FKey write FKey; property Path: string read FPath write FPath; end; TJvAutoSave = class(TPersistent) private FAutoSave: Boolean; FRegistry: TJvRegAutoSave; FParent: TComponent; protected function CanLoadSave: Boolean; public constructor Create(Parent: TComponent); destructor Destroy; override; procedure SaveValue(Value: Integer); overload; procedure SaveValue(Value: Double); overload; procedure SaveValue(Value: Boolean); overload; procedure SaveValue(Value: string); overload; function LoadValue(var Default: Integer): Boolean; overload; function LoadValue(var Default: Double): Boolean; overload; function LoadValue(var Default: Boolean): Boolean; overload; function LoadValue(var Default: string): Boolean; overload; published property Active: Boolean read FAutoSave write FAutoSave default False; property Registry: TJvRegAutoSave read FRegistry write FRegistry; end; implementation constructor TJvAutoSave.Create(Parent: TComponent); begin inherited Create; FAutoSave := False; FRegistry := TJvRegAutoSave.Create; FParent := Parent; end; destructor TJvAutoSave.Destroy; begin FRegistry.Free; inherited Destroy; end; function TJvAutoSave.CanLoadSave: Boolean; begin Result := False; if not (csDesigning in FParent.ComponentState) then if (FAutoSave) and (Registry.Key <> '') and (Registry.Path <> '') then Result := True; end; procedure TJvAutoSave.SaveValue(Value: Double); begin if CanLoadSave then with TRegistry.Create do begin OpenKey(Registry.Path, True); WriteFloat(Registry.Key, Value); Free; end; end; procedure TJvAutoSave.SaveValue(Value: Integer); begin if CanLoadSave then with TRegistry.Create do begin OpenKey(Registry.Path, True); WriteInteger(Registry.Key, Value); Free; end; end; function TJvAutoSave.LoadValue(var Default: Integer): Boolean; begin Result := False; if CanLoadSave then with TRegistry.Create do begin OpenKey(Registry.Path, True); if ValueExists(Registry.Key) then try Default := ReadInteger(Registry.Key); Result := True; except end; Free; end; end; function TJvAutoSave.LoadValue(var Default: Double): Boolean; begin Result := False; if CanLoadSave then with TRegistry.Create do begin OpenKey(Registry.Path, True); if ValueExists(Registry.Key) then try Default := ReadFloat(Registry.Key); Result := True; except end; Free; end; end; function TJvAutoSave.LoadValue(var Default: Boolean): Boolean; begin Result := False; if CanLoadSave then with TRegistry.Create do begin OpenKey(Registry.Path, True); if ValueExists(Registry.Key) then try Default := ReadBool(Registry.Key); Result := True; except end; Free; end; end; function TJvAutoSave.LoadValue(var Default: string): Boolean; begin Result := False; if CanLoadSave then with TRegistry.Create do begin OpenKey(Registry.Path, True); if ValueExists(Registry.Key) then try Default := ReadString(Registry.Key); Result := True; except end; Free; end; end; procedure TJvAutoSave.SaveValue(Value: string); begin if CanLoadSave then with TRegistry.Create do begin OpenKey(Registry.Path, True); WriteString(Registry.Key, Value); Free; end; end; procedure TJvAutoSave.SaveValue(Value: Boolean); begin if CanLoadSave then with TRegistry.Create do begin OpenKey(Registry.Path, True); WriteBool(Registry.Key, Value); Free; end; end; end. --- NEW FILE: JvInterpreter_JvRegAuto.pas --- {----------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: JvInterpreter.PAS, released on 2002-07-04. The Initial Developers of the Original Code are: Andrei Prygounkov <a.p...@gm...> Copyright (c) 1999, 2002 Andrei Prygounkov All Rights Reserved. Contributor(s): Last Modified: 2002-07-04 You may retrieve the latest version of this file at the Project JEDI's JVCL home page, located at http://jvcl.sourceforge.net Description : adapter unit - converts JvInterpreter calls to delphi calls Known Issues: -----------------------------------------------------------------------------} {$I JVCL.INC} unit JvInterpreter_JvRegAuto; interface uses JvInterpreter; procedure RegisterJvInterpreterAdapter(JvInterpreterAdapter: TJvInterpreterAdapter); implementation uses Classes; { TJvRegAuto } { constructor Create(AOwner: TComponent) } procedure TRegAuto_Create(var Value: Variant; Args: TJvInterpreterArgs); begin Value := O2V(TJvRegAuto.Create(V2O(Args.Values[0]) as TComponent)); end; { procedure Save; } procedure TRegAuto_Save(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).Save; end; { procedure Load; } procedure TRegAuto_Load(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).Load; end; {$IFDEF COMPLIB_VCL} { function ReadRootString(const Section, Ident, Default: string): string; } procedure TRegAuto_ReadRootString(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).ReadRootString(Args.Values[0], Args.Values[1], Args.Values[2]); end; { function ReadRootInteger(const Section, Ident: string; Default: Longint): Longint; } procedure TRegAuto_ReadRootInteger(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).ReadRootInteger(Args.Values[0], Args.Values[1], Args.Values[2]); end; { procedure WriteRootString(const Section, Ident, Value: string); } procedure TRegAuto_WriteRootString(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).WriteRootString(Args.Values[0], Args.Values[1], Args.Values[2]); end; { procedure WriteRootInteger(const Section, Ident: string; Value: Longint); } procedure TRegAuto_WriteRootInteger(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).WriteRootInteger(Args.Values[0], Args.Values[1], Args.Values[2]); end; {$ENDIF COMPLIB_VCL} { function ReadString(const Section, Ident, Default: string): string; } procedure TRegAuto_ReadString(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).ReadString(Args.Values[0], Args.Values[1], Args.Values[2]); end; { procedure WriteString(const Section, Ident, Value: String); } procedure TRegAuto_WriteString(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).WriteString(Args.Values[0], Args.Values[1], Args.Values[2]); end; { function ReadInteger(const Section, Ident: string; Default: Longint): Longint; } procedure TRegAuto_ReadInteger(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).ReadInteger(Args.Values[0], Args.Values[1], Args.Values[2]); end; { procedure WriteInteger(const Section, Ident: string; Value: Longint); } procedure TRegAuto_WriteInteger(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).WriteInteger(Args.Values[0], Args.Values[1], Args.Values[2]); end; { function ReadBool(const Section, Ident: string; Default: Boolean): Boolean; } procedure TRegAuto_ReadBool(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).ReadBool(Args.Values[0], Args.Values[1], Args.Values[2]); end; { procedure WriteBool(const Section, Ident: string; Value: Boolean); } procedure TRegAuto_WriteBool(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).WriteBool(Args.Values[0], Args.Values[1], Args.Values[2]); end; { function ReadFloat(const Section, Ident: string; Default: Double): Double; } procedure TRegAuto_ReadFloat(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).ReadFloat(Args.Values[0], Args.Values[1], Args.Values[2]); end; { procedure WriteFloat(const Section, Ident: string; Value: Double); } procedure TRegAuto_WriteFloat(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).WriteFloat(Args.Values[0], Args.Values[1], Args.Values[2]); end; { procedure ReadStrings(const Section, Ident: string; Strings: TStrings); } procedure TRegAuto_ReadStrings(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).ReadStrings(Args.Values[0], Args.Values[1], V2O(Args.Values[2]) as TStrings); end; { procedure WriteStrings(const Section, Ident: string; Value: TStrings); } procedure TRegAuto_WriteStrings(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).WriteStrings(Args.Values[0], Args.Values[1], V2O(Args.Values[2]) as TStrings); end; { procedure ReadSection(const Section: string; Ss: TStrings); } procedure TRegAuto_ReadSection(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).ReadSection(Args.Values[0], V2O(Args.Values[1]) as TStrings); end; { procedure ReadSections(Ss: TStrings); } procedure TRegAuto_ReadSections(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).ReadSections(V2O(Args.Values[0]) as TStrings); end; { procedure EraseSection(const Section: string); } procedure TRegAuto_EraseSection(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).EraseSection(Args.Values[0]); end; { procedure DeleteKey(const Section, Ident: string); } procedure TRegAuto_DeleteKey(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).DeleteKey(Args.Values[0], Args.Values[1]); end; { procedure ReadWholeSection(const Section: string; Ss: TStrings); } procedure TRegAuto_ReadWholeSection(var Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).ReadWholeSection(Args.Values[0], V2O(Args.Values[1]) as TStrings); end; { property Read UseReg: Boolean } procedure TRegAuto_Read_UseReg(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).UseReg; end; { property Write UseReg(Value: Boolean) } procedure TRegAuto_Write_UseReg(const Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).UseReg := Value; end; { property Read UseIni: Boolean } procedure TRegAuto_Read_UseIni(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).UseIni; end; { property Write UseIni(Value: Boolean) } procedure TRegAuto_Write_UseIni(const Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).UseIni := Value; end; { property Read UseStr: Boolean } procedure TRegAuto_Read_UseStr(var Value: Variant; Args: TJvInterpreterArgs); begin Value := TJvRegAuto(Args.Obj).UseStr; end; { property Write UseStr(Value: Boolean) } procedure TRegAuto_Write_UseStr(const Value: Variant; Args: TJvInterpreterArgs); begin TJvRegAuto(Args.Obj).UseStr := Value; end; procedure RegisterJvInterpreterAdapter(JvInterpreterAdapter: TJvInterpreterAdapter); const cJvRegAuto = 'JvRegAuto'; begin with JvInterpreterAdapter do begin { TJvRegAuto } AddClass(cJvRegAuto, TJvRegAuto, 'TJvRegAuto'); AddGet(TJvRegAuto, 'Create', TRegAuto_Create, 1, [varEmpty], varEmpty); AddGet(TJvRegAuto, 'Save', TRegAuto_Save, 0, [0], varEmpty); AddGet(TJvRegAuto, 'Load', TRegAuto_Load, 0, [0], varEmpty); {$IFDEF COMPLIB_VCL} AddGet(TJvRegAuto, 'ReadRootString', TRegAuto_ReadRootString, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'ReadRootInteger', TRegAuto_ReadRootInteger, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'WriteRootString', TRegAuto_WriteRootString, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'WriteRootInteger', TRegAuto_WriteRootInteger, 3, [varEmpty, varEmpty, varEmpty], varEmpty); {$ENDIF COMPLIB_VCL} AddGet(TJvRegAuto, 'ReadString', TRegAuto_ReadString, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'WriteString', TRegAuto_WriteString, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'ReadInteger', TRegAuto_ReadInteger, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'WriteInteger', TRegAuto_WriteInteger, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'ReadBool', TRegAuto_ReadBool, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'WriteBool', TRegAuto_WriteBool, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'ReadFloat', TRegAuto_ReadFloat, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'WriteFloat', TRegAuto_WriteFloat, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'ReadStrings', TRegAuto_ReadStrings, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'WriteStrings', TRegAuto_WriteStrings, 3, [varEmpty, varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'ReadSection', TRegAuto_ReadSection, 2, [varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'ReadSections', TRegAuto_ReadSections, 1, [varEmpty], varEmpty); AddGet(TJvRegAuto, 'EraseSection', TRegAuto_EraseSection, 1, [varEmpty], varEmpty); AddGet(TJvRegAuto, 'DeleteKey', TRegAuto_DeleteKey, 2, [varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'ReadWholeSection', TRegAuto_ReadWholeSection, 2, [varEmpty, varEmpty], varEmpty); AddGet(TJvRegAuto, 'UseReg', TRegAuto_Read_UseReg, 0, [0], varBoolean); AddSet(TJvRegAuto, 'UseReg', TRegAuto_Write_UseReg, 0, [varBoolean]); AddGet(TJvRegAuto, 'UseIni', TRegAuto_Read_UseIni, 0, [0], varBoolean); AddSet(TJvRegAuto, 'UseIni', TRegAuto_Write_UseIni, 0, [varBoolean]); AddGet(TJvRegAuto, 'UseStr', TRegAuto_Read_UseStr, 0, [0], varBoolean); AddSet(TJvRegAuto, 'UseStr', TRegAuto_Write_UseStr, 0, [varBoolean]); { EJvRegAutoError } AddClass(cJvRegAuto, EJvRegAutoError, 'EJvRegAutoError '); end; RegisterClasses([TJvRegAuto]); end; end. --- NEW FILE: JvRegAuto.pas --- {----------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: JvRegAuto.PAS, released on 2002-07-04. The Initial Developers of the Original Code are: Andrei Prygounkov <a.p...@gm...> Copyright (c) 1999, 2002 Andrei Prygounkov All Rights Reserved. Contributor(s): Last Modified: 2002-07-04 [...1316 lines suppressed...] try Ss.Clear; Inc(F); while F < Count do begin S := Strings[F]; if (Length(S) > 0) and (Trim(S[1]) = '[') then Break; Ss.Add(S); Inc(F); end; finally Ss.EndUpdate; end; end; end; end; end. --- NEW FILE: JvRegAutoEditorForm.dfm --- object JvRegEditor: TJvRegEditor Left = 211 Top = 120 Width = 460 Height = 359 BorderIcons = [biSystemMenu] Caption = 'RegAuto Editor' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] Icon.Data = { 0000010001001010100001001000280100001600000028000000100000002000 00000100040000000000C0000000000000000000000000000000000000000000 0000000080000080000000808000800000008000800080800000C0C0C0008080 80000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF000000 00000000000000000BBBB0000000000BB000BB000000000BB0000B000000000B BB000BB00000000BBB000BB00000000000000BB00000000000000BB000000000 00000BB00000000000000BB00000000000000BB00000000000000BB000000000 00000BB0000000000000BBBB00000000000BBBBBB0000000000000000000FFFF 0000F87F0000E73F0000E7BF0000E39F0000E39F0000FF9F0000FF9F0000FF9F 0000FF9F0000FF9F0000FF9F0000FF9F0000FF0F0000FE070000FFFF0000} OldCreateOrder = True ShowHint = True OnClose = FormClose OnCreate = FormCreate OnResize = FormResize OnShow = FormShow PixelsPerInch = 96 TextHeight = 13 object panelBottom: TPanel Left = 0 Top = 302 Width = 452 Height = 30 Align = alBottom BevelOuter = bvNone TabOrder = 0 object panelOKCancelApply: TPanel Left = 294 Top = 0 Width = 158 Height = 30 Align = alRight BevelOuter = bvNone TabOrder = 0 object btnOk: TButton Left = 1 Top = 4 Width = 73 Height = 24 Anchors = [akLeft, akRight, akBottom] Caption = '&OK' TabOrder = 0 OnClick = btnOkClick end object btnCancel: TButton Left = 80 Top = 4 Width = 73 Height = 24 Anchors = [akRight, akBottom] Caption = 'Cancel' ModalResult = 2 TabOrder = 1 OnClick = btnCancelClick end end end object panelTop: TPanel Left = 0 Top = 0 Width = 452 Height = 36 Align = alTop BevelOuter = bvNone TabOrder = 1 object Bevel1: TBevel Left = 0 Top = 32 Width = 452 Height = 4 Align = alBottom Shape = bsTopLine end object panelButtons: TPanel Left = 424 Top = 0 Width = 28 Height = 32 Align = alRight BevelOuter = bvNone TabOrder = 0 object btnAddProp: TSpeedButton Left = 2 Top = 3 Width = 25 Height = 25 Hint = 'Add / Delete property' Anchors = [akTop, akRight] Glyph.Data = { 36060000424D3606000000000000360400002800000020000000100000000100 0800000000000002000000000000000000000001000000010000000000000000 80000080000000808000800000008000800080800000C0C0C000C0DCC000F0CA A600000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000F0FBFF00A4A0A000808080000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00030303030303 0300000303030303030303030303030303F8F803FFFF03030303030303030303 0300FF0000030303030303030303030303F803F8F803FFFF0303030303030303 00FFFFFFFF0000030303030303030303F8FF030303F8F803FFFF030303030303 00FFFFFFFFFFFF000003030303030303F80303FFFF0303F8F803030303030300 FFFF0000FFFFFFFF07000303030303F8FF03F8F803FF030303F8030303030300 FFFFFFFF00FFFFFFFF0003FFFFFFFFF8FFFFFF03F80303FF03F8000000000000 0000FFFFFFFF00FFFF00F8F8F8F8F8F8F8F803FFFF03F80303F8000000000000 00000000FFFFFFFFFF00F8FFFFFFFFFFFF03F8F8FFFFFF0303F800FCFCFCFCFC 000000000000FFFF0003F8F8F8F8F8F8030303F8F8F803FFF8030000FCFCFC00 00000000030300000300F8FFF8F8F803030303F8FF03F8F803F8000000FC0000 00000000030303030300F8FF03F803030303FFF8FF03030303F8000000000000 F8FBF800030303030300F8FFFFFFFF0303F8FFF8FF03030303F800F9F9F90000 FBFBFB00030303030300F8F8F8F8FF03F8F8F8F8FFFF030303F800F9F9F90000 F8FBF800000303030003F8F8F8F8FF0303F803F8F803FFFFF80300F9F9F90000 00000000030000000303F8F8F8F8FFFFFFFFFFF8FFF8F8F80303000000000000 00000000030303030303F8F8F8F8F8F8F8F8F8F8030303030303} NumGlyphs = 2 OnClick = btnAddPropClick end end object edtProp: TEdit Left = 1 Top = 7 Width = 312 Height = 21 Hint = 'The name of property can be entered directly here' TabOrder = 1 OnChange = edtPropChange OnEnter = ListEnter OnKeyPress = edtPropKeyPress end end object Tree: TTreeView Left = 0 Top = 36 Width = 201 Height = 266 Hint = 'Accessible properties' Align = alLeft Ctl3D = True DragMode = dmAutomatic Indent = 27 ParentCtl3D = False ReadOnly = True TabOrder = 2 OnChange = TreeChange OnDragDrop = TreeDragDrop OnDragOver = TreeDragOver OnEnter = TreeEnter Items.Data = { 030000001C00000001000000FFFFFFFFFFFFFFFFFFFFFFFF0000000000000000 033132321F000000FFFFFFFF00000000FFFFFFFFFFFFFFFF0000000000000000 063333353435341D0000000300000000000000FFFFFFFFFFFFFFFF0000000001 00000004313132321C0000000000000000000000FFFFFFFFFFFFFFFF00000000 0000000003323334} end object List: TListBox Left = 201 Top = 36 Width = 251 Height = 266 Hint = 'List of saved properties' Align = alClient Ctl3D = True DragMode = dmAutomatic ExtendedSelect = False ItemHeight = 13 ParentCtl3D = False PopupMenu = PopupMenu1 TabOrder = 3 TabWidth = 10 OnClick = ListClick OnDragDrop = ListDragDrop OnDragOver = ListDragOver OnDrawItem = ListDrawItem OnEnter = ListEnter OnKeyUp = ListKeyUp end object TreeImages: TImageList Height = 24 Width = 24 Left = 42 Top = 134 end object PopupMenu1: TPopupMenu Left = 248 Top = 136 object Sort1: TMenuItem Caption = 'Sort' OnClick = Sort1Click end end end --- NEW FILE: JvRegAutoEditorForm.pas --- {----------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: JvRegAutoEditorForm.PAS, released on 2002-07-04. The Initial Developers of the Original Code are: Andrei Prygounkov <a.p...@gm...> Copyright (c) 1999, 2002 Andrei Prygounkov All Rights Reserved. Contributor(s): Last Modified: 2002-07-04 You may retrieve the latest version of this file at the Project JEDI's JVCL home page, located at http://jvcl.sourceforge.net description : Design-time Editor for TJvRegAuto component Known Issues: Some russian comments were translated to english; these comments are marked with [translated] -----------------------------------------------------------------------------} {$I JVCL.INC} unit JvRegAutoEditorForm; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls, ExtCtrls, ComCtrls, Buttons, Menus, {$IFDEF COMPILER6_UP} DesignIntf, DesignEditors, {$ELSE} DsgnIntf, {$ENDIF COMPILER6_UP} {$IFDEF COMPILER4_UP} ImgList, {$ENDIF COMPILER4_UP} JvRegAuto, JvComponent; type TJvRegAutoEditor = class(TComponentEditor) function GetVerbCount: Integer; override; function GetVerb(Index: Integer): string; override; procedure ExecuteVerb(Index: Integer); override; end; TJvRegEditor = class(TForm) panelBottom: TPanel; panelTop: TPanel; panelOKCancelApply: TPanel; btnOk: TButton; btnCancel: TButton; panelButtons: TPanel; edtProp: TEdit; TreeImages: TImageList; Tree: TTreeView; btnAddProp: TSpeedButton; List: TListBox; PopupMenu1: TPopupMenu; Sort1: TMenuItem; procedure btnOkClick(Sender: TObject); procedure btnCancelClick(Sender: TObject); procedure FormResize(Sender: TObject); procedure FormShow(Sender: TObject); procedure TreeChange(Sender: TObject; Node: TTreeNode); procedure btnAddPropClick(Sender: TObject); procedure ListKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure ListClick(Sender: TObject); procedure TreeEnter(Sender: TObject); procedure ListDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure FormCreate(Sender: TObject); procedure edtPropChange(Sender: TObject); procedure edtPropKeyPress(Sender: TObject; var Key: Char); procedure ListDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure ListDragDrop(Sender, Source: TObject; X, Y: Integer); procedure TreeDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure TreeDragDrop(Sender, Source: TObject; X, Y: Integer); procedure ListEnter(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Sort1Click(Sender: TObject); private Component: TJvRegAuto; FProps: string; FModified: Boolean; procedure Apply; procedure TreeLoad; procedure ListLoad; procedure PropAdd; procedure PropDelete; procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO; public constructor Create1(AOwner: TComponent; lComponent: TComponent); property Modified: Boolean read FModified; end; implementation uses JvConsts, TypInfo, ExptIntf, JvDsgnIntf; {$R *.DFM} //=== TJvRegAutoEditor ======================================================= function TJvRegAutoEditor.GetVerbCount: Integer; begin Result := inherited GetVerbCount + 1; end; function TJvRegAutoEditor.GetVerb(Index: Integer): string; begin if Index = GetVerbCount - 1 then Result := 'Editor' else Result := inherited GetVerb(Index); end; procedure TJvRegAutoEditor.ExecuteVerb(Index: Integer); var RegEditor: TJvRegEditor; begin if Index = GetVerbCount - 1 then begin RegEditor := TJvRegEditor.Create1(nil, Component); try RegEditor.ShowModal; if RegEditor.Modified then Designer.Modified; finally RegEditor.Free; end end else inherited ExecuteVerb(Index); end; //=== TJvLoadProgress ======================================================== type TJvLoadProgress = class(TForm) ProgressBar: TProgressBar; procedure btnCancelClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); public Canceled: Boolean; end; var LoadProgress: TJvLoadProgress; const // Indexes of pictures in TreeImages [translated] imUnknown = 4; imClass = 4; imInteger = 1; imChar = 1; imString = 1; imEnumeration = 1; imComponent = 3; // With this picture start komponety [translated] function LoadProgressCreate: TJvLoadProgress; begin {$IFDEF DELPHI} Result := TJvLoadProgress.CreateNew(Application); {$ELSE} Result := TJvLoadProgress.CreateNew(Application, 1); {$ENDIF} with Result do begin OnClose := FormClose; Width := 279; Height := 148; BorderStyle := bsDialog; Position := poScreenCenter; Caption := 'JvRegAuto Editor'; with TLabel.Create(Result) do begin Parent := Result; Caption := 'Reading RTTI'; Left := 68; Top := 16; Font.Size := 10; Font.Style := [fsBold]; end; with TButton.Create(Result) do begin Parent := Result; Left := 96; Top := 88; Caption := 'Cancel'; OnClick := btnCancelClick; end; ProgressBar := TProgressBar.Create(Result); with ProgressBar do begin Parent := Result; SetBounds(7, 56, 257, 18); end; Canceled := False; end; end; procedure TJvLoadProgress.btnCancelClick(Sender: TObject); begin Canceled := True; end; procedure TJvLoadProgress.FormClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; end; //=== TJvRegEditor =========================================================== constructor TJvRegEditor.Create1(AOwner: TComponent; lComponent: TComponent); begin inherited Create(AOwner); Component := lComponent as TJvRegAuto; FProps := Component.Props.Text; FModified := False; end; procedure TJvRegEditor.btnOkClick(Sender: TObject); begin Apply; Close; end; procedure TJvRegEditor.btnCancelClick(Sender: TObject); begin Close; end; procedure TJvRegEditor.Apply; begin Component.Props := List.Items; end; procedure TJvRegEditor.FormShow(Sender: TObject); begin LoadProgress := LoadProgressCreate; try LoadProgress.Show; TreeLoad; finally LoadProgress.Close; end; ListLoad; end; procedure TJvRegEditor.ListLoad; begin List.Items.Assign(Component.Props); end; function IsEnabled(S: ShortString): Boolean; var P: Integer; begin P := Pos(#0, S); Result := not ((P = 0) or (Length(S) <= P) or (S[P + 1] = 'N')); end; procedure TJvRegEditor.TreeLoad; const SOrdType: array [0..5] of PChar = ('Shortint', 'Byte', 'Integer', 'Word', 'Longint', 'Cardinal'); SFloatType: array [0..4] of PChar = ('Single', 'Double', 'Extended', 'Comp', 'Currency'); var I, J: Integer; ANode: TTreeNode; TypeInf: PTypeInfo; TypeData: PTypeData; PropList: PPropList; NumProps: word; AName: string; CompList: TList; Comp: TComponent; procedure AddToTree(AComponent: TComponent; APropInfo: PPropInfo; Node: TTreeNode); var ATypeInfo: PTypeInfo; aPropList: PPropList; aNumProps: Word; I: Integer; MyNode: TTreeNode; begin ATypeInfo := APropInfo^.PropType^; TypeData := GetTypeData(ATypeInfo); MyNode := nil; with ATypeInfo^ do case Kind of tkUnknown: begin MyNode := Tree.Items.AddChild(Node, 'Unknown - ' + AName + #0 + 'N'); MyNode.ImageIndex := imUnknown; // Picture - Not possible to select [translated] end; tkInteger: begin MyNode := Tree.Items.AddChild(Node, AName + ' : ' + SOrdType[Integer(TypeData^.OrdType)] + #0 + 'Y'); MyNode.ImageIndex := imInteger; // Picture - Possible to select [translated] end; tkFloat: begin MyNode := Tree.Items.AddChild(Node, AName + ' : ' + SFloatType[Integer(TypeData^.FloatType)] + #0 + 'Y'); MyNode.ImageIndex := imInteger; // Picture - Possible to select [translated] end; tkWChar, tkChar: begin MyNode := Tree.Items.AddChild(Node, AName + ' : ' + System.Copy(GetEnumName(TypeInfo(TTypeKind) , Integer(Kind)), 3, 255) + #0 + 'Y'); MyNode.ImageIndex := imChar; // Picture - Possible to select [translated] end; tkEnumeration: begin MyNode := Tree.Items.AddChild(Node, AName + ' : ' + ATypeInfo^.Name + #0 + 'Y'); MyNode.ImageIndex := imEnumeration; // Picture - Possible to select [translated] end; tkString, tkLString {, tkWString}: begin MyNode := Tree.Items.AddChild(Node, AName + ' : ' + ATypeInfo^.Name + ' ( ' + Format('String[%d]', [TypeData^.MaxLength]) + ' )' + #0 + 'Y'); MyNode.ImageIndex := imString; // Picture - Possible to select [translated] end; tkClass: begin MyNode := Tree.Items.AddChild(Node, AName + ' : ' + TypeData^.ClassType.ClassName + #0 + 'N'); MyNode.ImageIndex := imClass; // Picture - Possible to select [translated] AComponent := TComponent(GetOrdProp(AComponent, APropInfo)); { Protection against recursive references of components [translated] } if (AComponent = nil) or (CompList.IndexOf(AComponent) > -1) then Exit; CompList.Add(AComponent); aNumProps := TypeData^.PropCount; GetMem(aPropList, aNumProps * SizeOf(Pointer)); try GetPropInfos(ATypeInfo, aPropList); for I := 0 to aNumProps - 1 do begin AName := aPropList^[I]^.Name; AddToTree(AComponent, aPropList^[I], MyNode); end; finally FreeMem(aPropList, aNumProps * SizeOf(Pointer)); end; end; // tkSet // - Not yet supported [translated] end; if MyNode <> nil then MyNode.SelectedIndex := MyNode.ImageIndex; end; procedure LoadBitmap; var Pic, PicTmp: TBitmap; s: string; begin if not (csDesigning in ComponentState) then Exit; Pic := TBitmap.Create; s := Comp.ClassName; try Pic.LoadFromResourceName(hInstance, UpperCase(pchar(s))); except end; if (Pic.Height <> 24) or (Pic.Width <> 24) then begin PicTmp := TBitmap.Create; PicTmp.Height := 24; PicTmp.Width := 24; PicTmp.Canvas.Draw(0, 0, Pic); Pic.Free; Pic := PicTmp; end; TreeImages.AddMasked(Pic, clOlive); Pic.Free; end; begin CompList := TList.Create; Tree.Items.BeginUpdate; try Tree.Items.Clear; LoadProgress.ProgressBar.Max := Component.Owner.ComponentCount + 2; for J := -1 to Component.Owner.ComponentCount - 1 do begin if J = -1 then Comp := Component.Owner else Comp := Component.Owner.Components[J]; LoadProgress.ProgressBar.Position := J + 1; Application.ProcessMessages; if LoadProgress.Canceled then Exit; //ODS('Read ' + Comp.Name + ':' + Comp.ClassName); LoadBitmap; ANode := Tree.Items.Add(nil, Comp.Name + ' : ' + Comp.ClassName); // else ANode := Tree.Items.Add(nil, Component.Owner.Components[J].Name +' : '+ Component.Owner.Components[J].ClassName); ANode.ImageIndex := imComponent + J + 1; ANode.SelectedIndex := ANode.ImageIndex; try TypeInf := Comp.ClassInfo; AName := TypeInf^.Name; TypeData := GetTypeData(TypeInf); NumProps := TypeData^.PropCount; GetMem(PropList, NumProps * SizeOf(Pointer)); try GetPropInfos(TypeInf, PropList); for I := 0 to NumProps - 1 do begin AName := PropList^[I]^.Name; CompList.Clear; CompList.Add(Comp); AddToTree(Comp, PropList^[I], ANode); end; finally FreeMem(PropList, NumProps * SizeOf(Pointer)); end; except on E: Exception do begin E.Message := 'JvRegAutoEditorForm error:' + E.Message; raise; end; end; end; // Tree.AlphaSort; finally CompList.Free; Tree.Items.EndUpdate; end; end; procedure TJvRegEditor.FormResize(Sender: TObject); begin edtProp.Width := panelButtons.Left - edtProp.Left * 2 - 2; end; procedure TJvRegEditor.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); begin inherited; Msg.MinMaxInfo^.ptMinTrackSize.X := panelOKCancelApply.Width + 15; Msg.MinMaxInfo^.ptMinTrackSize.Y := 200; end; procedure TJvRegEditor.TreeChange(Sender: TObject; Node: TTreeNode); var Text, Text1: string; P: Integer; begin if Node = nil then Exit; Text := Node.Text; btnAddProp.Enabled := IsEnabled(Text); P := Pos(' ', Text); if P > 0 then Text := System.Copy(Text, 1, P - 1); Node := Node.Parent; while Node <> nil do begin Text1 := Node.Text; P := Pos(' ', Text1); if P > 0 then Text1 := System.Copy(Text1, 1, P - 1); Text := Text1 + '.' + Text; Node := Node.Parent; end; edtProp.Text := Text; { Ind := List.Items.IndexOf(edtProp.Text); if Ind <> -1 then List.ItemIndex := Ind;} end; procedure TJvRegEditor.btnAddPropClick(Sender: TObject); var Ind: Integer; begin Ind := List.Items.IndexOf(edtProp.Text); if Ind = -1 then PropAdd else if ActiveControl = List then PropDelete else begin List.Items.Delete(Ind); List.ItemIndex := Ind; end; end; procedure TJvRegEditor.PropAdd; begin if List.Items.IndexOf(edtProp.Text) = -1 then begin List.Items.Add(edtProp.Text); List.ItemIndex := List.Items.IndexOf(edtProp.Text); end; end; procedure TJvRegEditor.PropDelete; var It: Integer; begin It := List.ItemIndex; List.Items.Delete(List.ItemIndex); if It > List.Items.Count - 1 then dec(It); if It < 0 then It := 0; List.ItemIndex := It; if List.Items.Count <> 0 then edtProp.Text := List.Items[List.ItemIndex]; end; procedure TJvRegEditor.ListKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_DELETE then PropDelete; if List.Items.Count <> 0 then edtProp.Text := List.Items[List.ItemIndex]; end; procedure TJvRegEditor.ListClick(Sender: TObject); begin edtProp.Text := List.Items[List.ItemIndex]; end; procedure TJvRegEditor.TreeEnter(Sender: TObject); begin TreeChange(Sender, Tree.Selected); end; procedure TJvRegEditor.ListDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var Offset: Integer; { text offset width } BitmapIndex: Integer; ComponentName: string[100]; Obj: TComponent; begin (Control as TListBox).Canvas.FillRect(Rect); { clear the rectangle } if Tree.Images <> nil then begin ComponentName := (Control as TListBox).Items[Index]; ComponentName := Copy(ComponentName, 1, Pos('.', ComponentName) - 1); if ComponentName = Component.Owner.Name then ComponentName := ''; if ComponentName = '' then BitmapIndex := 0 else begin Obj := Component.Owner.FindComponent(ComponentName); if Obj <> nil then BitmapIndex := Obj.ComponentIndex + 1 else BitmapIndex := imUnknown; end; inc(BitmapIndex, imComponent); TreeImages.Draw((Control as TListBox).Canvas, Rect.Left + 2, Rect.Top, BitmapIndex); Offset := TreeImages.width + 6; { add four pixels between bitmap and text } end else Offset := 2; (Control as TListBox).Canvas.TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index]); { display the text } //Note that the Rect parameter automatically provides the proper location of the item within the control's canvas. end; procedure TJvRegEditor.FormCreate(Sender: TObject); begin // if Tree.Images = nil then List.Style := lbStandard; with TSplitter.Create(Self) do begin Parent := Self; Align := alLeft; Left := 201; Beveled := False; Visible := True; end; with TJvRegAuto.Create(Self) do begin {$IFDEF DELPHI} RegPath := 'Software\Borland\Delphi\JVCL\JvRegAutoEditorForm'; {$ENDIF DELPHI} {$IFDEF CBUILDER} RegPath := 'Software\Borland\C++Builder\JVCL\JvRegAutoEditorForm'; {$ENDIF CBUILDER} AutoMode := True; SaveWindowPlace := True; Props.Add('Tree.Width'); Load; end; edtProp.Hint := sRegAutoEditorEdtPropHint; Tree.Hint := sRegAutoEditorTreeHint; List.Hint := sRegAutoEditorListHint; btnAddProp.Hint := sRegAutoEditorBtnAddPropHint; Sort1.Caption := sRegAutoEditorSort; end; procedure TJvRegEditor.edtPropChange(Sender: TObject); var Ind: Integer; begin Ind := List.Items.IndexOf(edtProp.Text); if Ind <> -1 then List.ItemIndex := Ind; end; procedure TJvRegEditor.edtPropKeyPress(Sender: TObject; var Key: Char); begin if Key = ^M then begin btnAddPropClick(Sender); Key := #0; end; end; procedure TJvRegEditor.ListDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin Accept := (Source = Tree) and (List.Items.IndexOf(edtProp.Text) = -1); end; procedure TJvRegEditor.ListDragDrop(Sender, Source: TObject; X, Y: Integer); begin if (Source = Tree) and (List.Items.IndexOf(edtProp.Text) = -1) then btnAddPropClick(Self); // then PropAdd; end; procedure TJvRegEditor.TreeDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin Accept := (Source = List) and (List.Items.IndexOf(edtProp.Text) <> -1); end; procedure TJvRegEditor.TreeDragDrop(Sender, Source: TObject; X, Y: Integer); begin if (Source = List) and (List.Items.IndexOf(edtProp.Text) <> -1) then btnAddPropClick(Self); // then PropDelete; end; procedure TJvRegEditor.ListEnter(Sender: TObject); begin btnAddProp.Enabled := True; end; procedure TJvRegEditor.FormClose(Sender: TObject; var Action: TCloseAction); begin if FProps <> Component.Props.Text then FModified := True; end; procedure TJvRegEditor.Sort1Click(Sender: TObject); begin List.Sorted := True; // List.Sorted := False; end; function GetProjectName: string; begin if Assigned(ToolServices) then Result := ToolServices.GetProjectName else Result := ''; end; initialization GetProjectNameProc := GetProjectName; end. |