Link to home
Start Free TrialLog in
Avatar of PeterdeB
PeterdeBFlag for Netherlands

asked on

How to perform magic on this TEdit + TRegistry Issue?(2)

Hi my friends!

This is my code >

unit unMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, SUIForm, ShellApi, ShlObj, ActiveX,
  ComCtrls, SUIStatusBar,SUIButton, Menus, SUIMainMenu, GhostApp, ImgList,
  SUIDlg, SMLMsgLangRes, SMLMenuLangRes, SMLLangRes,
  SMLFormLangRes, GetSetRegData, Registry, FileCtrl, ExtCtrls;

type
  TMainfrm = class(TForm)
    frmMain: TsuiForm;
    lblTip: TLabel;
    sbMain: TsuiStatusBar;
    mnuNL: TsuiMainMenu;
    File1: TMenuItem;
    Exit1: TMenuItem;
    Help: TMenuItem;
    Help1: TMenuItem;
    About1: TMenuItem;
    GhostApp1: TGhostApp;
    btnOK: TsuiButton;
    btnReset: TsuiButton;
    pnlMain1: TPanel;
    pnlSub: TPanel;
    imgList: TImageList;
    lblOmschrijving: TLabel;
    msgDlg: TsuiMessageDialog;
    btn1: TsuiButton;
    btn2: TsuiButton;
    btn3: TsuiButton;
    btn4: TsuiButton;
    btn5: TsuiButton;
    ProgramIcon: TImage;
    lblApplication: TLabel;
    btnTest: TsuiButton;
    btnHelp: TsuiButton;
    lblVersion: TLabel;
    btnErase: TsuiButton;
    lblReleased: TLabel;
    lblCopyright: TLabel;
    smlFormLangRes1: TsmlFormLangRes;
    smlMenuLangRes1: TsmlMenuLangRes;
    smlMsgLangRes1: TsmlMsgLangRes;
    miLanguage1: TMenuItem;
    Nederlands1: TMenuItem;
    Engels1: TMenuItem;
    edt1: TEdit;
    edt2: TEdit;
    edt3: TEdit;
    edt4: TEdit;
    edt5: TEdit;
    OpenDialog1: TOpenDialog;
    pnlWarning: TPanel;
    imgWarning: TImage;
    lblWarning: TLabel;

    procedure btnResetClick(Sender: TObject);
    procedure btnTestClick(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure ApplicationHint(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure About1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure btnHelpClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Engels1Click(Sender: TObject);
    procedure Nederlands1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
  private
     FPaths:        Array [0..4] of String;
     FDisplay:      Array [0..4] of TEdit;
     FShowSplashRegardless: Boolean;
     FHelpFile, FAboutFile: string;
     procedure InitializeForm;
     property ShowSplashRegardless: Boolean read FShowSplashRegardless write FShowSplashRegardless;
     property HelpFile: string read FHelpFile write FHelpFile;
     property AboutFile: string read FAboutFile write FAboutFile;
  public
     procedure SetPath(Index: Integer; Value: String);
     function GetPath(Index: Integer): String;
  end;

var
  Mainfrm: TMainfrm;
  PlacesBar: string;
implementation

uses
  Splash, unAbout, unDialog, unStrings;

{$R *.dfm}

function TMainFrm.GetPath(Index: Integer): String;
begin

  // Check index
  if (Index in [0..4]) then
     // Return path value
     result:=FPaths[Index]
  else
     // Clear result
     SetLength(result, 0);

end;

procedure TMainFrm.SetPath(Index: Integer; Value: String);
begin

  // Check index
  if (Index in [0..4]) then
  begin
     // Set actual path value
     FPaths[Index]:=Value;
     // Change edit display value
     FDisplay[Index].Text:=MinimizeName(Value, Canvas, FDisplay[Index].Width);
  end;
end;


{- MODIFIED -----------------------------------------------------------------------------}
procedure TMainfrm.FormCreate(Sender: TObject);
var  dwIndex:       Integer;
begin

  // Set edit control array
  FDisplay[0]:=edt1;
  FDisplay[1]:=edt2;
  FDisplay[2]:=edt3;
  FDisplay[3]:=edt4;
  FDisplay[4]:=edt5;

  // Update the tag property for each edit
  for dwIndex:=0 to 4 do FDisplay[dwIndex].Tag:=dwIndex;

  if FileExists(ExtractFileDir(Application.Exename) + '\English.ini') then
    begin
        smlFormLangRes1.LangFileName := 'English.ini';
        smlMenuLangRes1.LangFileName := 'English.ini';
        smlMsgLangRes1.LangFileName := 'English.ini';
        Engels1.Checked := True;
        Nederlands1.Checked := False;
        HelpFile := ExtractFileDir(Application.Exename) + '\Help\ODPE_ENG.hlp';
        AboutFile := ExtractFileDir(Application.Exename) + '\Res\About_ENG.rtf'
    end
    else
    begin
        smlFormLangRes1.LangFileName := 'Nederlands.ini';
        smlMenuLangRes1.LangFileName := 'Nederlands.ini';
        smlMsgLangRes1.LangFileName := 'Nederlands.ini';
        Nederlands1.Checked := True;
        Engels1.Checked := False;
        HelpFile := ExtractFileDir(Application.Exename) + '\Help\ODPE_NL.hlp';
        AboutFile := ExtractFileDir(Application.Exename) + '\Res\About_NL.rtf'
    end;
  Application.MainForm.Caption := 'Open Dialog Places Bar Editor';
  lblApplication.Caption := sAppTitle;
  lblVersion.Caption := sVersion;
  lblCopyright.Caption := sCopyright;
  lblReleased.Caption := sReleaseNote;
   with Constraints do
  begin
    MaxWidth := Width;
    MaxHeight := Height;
    MinWidth := Width;
    MinHeight := Height;
  ShowSplashRegardless := True;
  InitializeForm;
end;
end;

{- MODIFIED-----------------------------------------------------------------------------}
procedure TMainfrm.InitializeForm;
var Reg: TRegistry;
     dwIndex: Integer;
begin

  PlacesBar := 'Software\Microsoft\Windows\CurrentVersion\Policies\Comdlg32\PlacesBar';
  Reg := TRegistry.Create(KEY_ALL_ACCESS);
  Reg.RootKey := HKEY_CURRENT_USER;
  if not Reg.KeyExists(PlacesBar)then
  WinExec('Regedt32.exe /s default.reg', SW_HIDE) else
  begin
     // Set each path, this also handles the translation of the path to a display
     // value for the desired edit control
     for dwIndex:=0 to 4 do SetPath(0, GetRegistryData(HKEY_CURRENT_USER,PlacesBar,'place'+IntToStr(dwIndex)));
  end;

end;
{------------------------------------------------------------------------------}
procedure TMainfrm.FormShow(Sender: TObject);
begin
  if ShowSplashRegardless then
    Sleep(1000);
  fSplash.Release;
end;
{------------------------------------------------------------------------------}
procedure TMainfrm.ApplicationHint(Sender: TObject);
begin
  sbmain.Panels[0].Text := (Application.Hint);
end;
{------------------------------------------------------------------------------}

{- MODIFIED -----------------------------------------------------------------------------}
procedure TMainfrm.ButtonClick(Sender: TObject);
var
  lpbi: TBrowseInfo;
  pidlStart: PItemIDList;
  Malloc: IMalloc;
  sFolder: string;
  pidlSelected: PItemIDList;
  Edit: TEdit;
begin
  SHGetSpecialFolderLocation(Handle, $11, pidlStart);
  SHGetMalloc(Malloc);
  with lpbi do
  begin
    hwndOwner := Handle;
    pidlRoot := pidlStart;
    GetMem(pszDisplayName, MAX_PATH);
    lpszTitle := PChar('Selecteer folder');
    ulFlags := $00000001;
    lpfn := nil;
  end;
  pidlSelected := SHBrowseForFolder(lpbi);
  if pidlSelected <> nil then
  begin
    if SHGetPathFromIDList(pidlSelected, lpbi.pszDisplayName) then
      sFolder := StrPas(lpbi.pszDisplayName);
    if (Sender is TsuiButton) then
    begin
      Edit := FindComponent('edt' + Copy((Sender as TsuiButton).Name, 4, 255)) as TEdit;
      Canvas.Font := Edit.Font;

        // Set the path using the index obtained from the edit contol's tag property
        SetPath(Edit.Tag, sFolder);

      Malloc.Free(pidlSelected);
    end;
    if lblWarning.Visible = False then
 lblWarning.Visible := True;
 if imgWarning.Visible = False
 then imgWarning.Visible := True;
    FreeMem(lpbi.pszDisplayName);
    Malloc.Free(pidlStart);
  end;
end;
{------------------------------------------------------------------------------}
procedure TMainfrm.Exit1Click(Sender: TObject);
begin
  close;
end;
{------------------------------------------------------------------------------}
procedure TMainfrm.About1Click(Sender: TObject);
begin
  Aboutbox.ShowModal;
end;
{------------------------------------------------------------------------------}
procedure TMainfrm.btnOKClick(Sender: TObject);
var  dwIndex:    Integer;
begin

  if (mrYes = MessageDlg('Alle wijzigingen worden opgeslagen. Doorgaan?', mtConfirmation, [mbYes, mbNo], 0)) then
  begin
     // Write the paths back to the registry. Use the GetPath(Index) function to
     // get the desired paths (not the display paths)
     for dwIndex:=0 to 4 do SetRegistryData(HKEY_CURRENT_USER, PlacesBar,'place'+IntToStr(dwIndex),rdString, GetPath(dwIndex));
     Close;
  end;

end;
{------------------------------------------------------------------------------}
procedure TMainfrm.btnResetClick(Sender: TObject);
const
  nicenames: array[1..5] of string = ('Recent', 'Desktop', 'MyDocuments', 'MyComputer',
    'MyNetworkPlaces');
    var i:Integer;
    edit: TEdit;
begin
if (mrYes = MessageDlg('Alle wijzigingen gaan verloren. Doorgaan?', mtConfirmation, [mbYes, mbNo], 0)) then
begin
 i := 1;
 while (i <= 5) do begin
edit :=  FindComponent('edt' + IntToStr(i)) As TEdit;
edit.Text := nicenames[i];
Inc(i);
end;
ShellExecute(0, nil, PChar(Application.ExeName), nil, nil, SW_NORMAL);
 Close;
end;
end;
{------------------------------------------------------------------------------}
procedure TMainfrm.btnTestClick(Sender: TObject);
begin
  OpenDialog1.Execute;
end;
{------------------------------------------------------------------------------}

{------------------------------------------------------------------------------}
procedure TMainfrm.btnHelpClick(Sender: TObject);
begin
  if not FileExists(HelpFile) then
    MessageDlg('Help bestand niet gevonden!', mtInformation, [mbOK],0)
  else
  begin
    Application.HelpFile := HelpFile;
    Application.HelpCommand(HELP_INDEX, 0);
  end;
end;
{------------------------------------------------------------------------------}

{------------------------------------------------------------------------------}
procedure TMainfrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if imgWarning.Visible  then
if (mrNo = MessageDlg('Wilt u het programma afsluiten en de wijzigingen opslaan?', mtConfirmation, [mbYes, mbNo], 0)) then
  begin
    CanClose := False;
end;
end;
{------------------------------------------------------------------------------}

procedure TMainfrm.Engels1Click(Sender: TObject);
begin
if smlFormLangRes1.LangFileName = 'Nederlands.ini' then
    begin
    smlFormLangRes1.LangFileName := 'English.ini';
        smlMenuLangRes1.LangFileName := 'English.ini';
        smlMsgLangRes1.LangFileName := 'English.ini';
        Engels1.Checked := True;
        Nederlands1.Checked := False;
        HelpFile := ExtractFileDir(Application.Exename) + '\Help\ODPE_ENG.hlp';
end;
end;

procedure TMainfrm.Nederlands1Click(Sender: TObject);
begin
 if smlFormLangRes1.LangFileName = 'English.ini' then
    begin
        smlFormLangRes1.LangFileName := 'Nederlands.ini';
        smlMenuLangRes1.LangFileName := 'Nederlands.ini';
        smlMsgLangRes1.LangFileName := 'Nederlands.ini';
        Nederlands1.Checked := True;
        Engels1.Checked := False;
        HelpFile := ExtractFileDir(Application.Exename) + '\Help\ODPE_NL.hlp';
end;
end;

{- MODIFIED -------------------------------------------------------------------}
procedure TMainfrm.FormClose(Sender: TObject; var Action: TCloseAction);
var  dwIndex:    Integer;
begin

  // Write the paths back to the registry. Use the GetPath(Index) function to
  // get the desired paths (not the display paths)
  for dwIndex:=0 to 4 do SetRegistryData(HKEY_CURRENT_USER, PlacesBar,'place'+IntToStr(dwIndex),rdString, GetPath(dwIndex));

end;

procedure TMainfrm.FormDestroy(Sender: TObject);
begin
 //
end;

end.


This is my reference >

https://www.experts-exchange.com/questions/22053619/How-to-perform-magic-on-this-TEdit-TRegistry-Issue.html

These are my kind regards!!

Paul :)
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Was your question not answered in the other link?
In the other question you say
"Ps PierreC > are you willing to reply to the other question (part 2) and show me how to create this component you mentioned?"

Is that what you want in this question, are you wanting help installing my suggested component for use in design time?
Avatar of PeterdeB

ASKER

Hi PierreC!

I would like your help with the creation of that component. This will then close the other question and you will be rewarded accordingly.

Kind regards,

Paul

Ps it would be great when I would have a TEdit which I can use as component in other projects > so I would like to install it into the IDE.
ASKER CERTIFIED SOLUTION
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is soo coool!! Thank you PierreC!!

Kind regards,

Paul ;-)
Glad to help.
The component thingie rocks to say the least! It also happens to be one of the most complex Delphi matters, for me to comprehend.

Thanks a lot my friend!

Regards,

Paul ;-)