Solved

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

Posted on 2006-11-08
7
475 Views
Last Modified: 2010-04-04
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 >

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_22053619.html

These are my kind regards!!

Paul :)
0
Comment
Question by:PeterdeB
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 17912455
Was your question not answered in the other link?
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 17912603
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?
0
 

Author Comment

by:PeterdeB
ID: 17912782
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.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 500 total points
ID: 17913915
Hi Paul.

1.) Save the following files below
2.) open EditShortenText_control.dpk in delphi
3.) click compile and install on the package screen

Regards
Pierre

EditShortenText_control.dpk
======================================================================
package EditShortenText_control;

{$R *.res}
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO ON}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST OFF}
{$MINENUMSIZE 1}
{$IMAGEBASE $400000}
{$DESCRIPTION 'TEdit control that shortens display text'}
{$IMPLICITBUILD OFF}

requires
  rtl,
  vcl;

contains
  EditShortenText in 'EditShortenText.pas';

end.


EditShortenText.pas
========================================================
unit EditShortenText;

interface

uses Windows, Messages, Classes, Graphics, Controls, StdCtrls;

type
  //You can change this class name to what you like
  // e.g. TEditShortenText
  TMyEdit = class(TCustomEdit)
    private
      FCanvas: TCanvas;
      procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
    protected
      property Canvas: TCanvas read FCanvas;
    public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
    published
      property Anchors;
      property AutoSelect;
      property AutoSize;
      property BevelEdges;
      property BevelInner;
      property BevelKind default bkNone;
      property BevelOuter;
      property BiDiMode;
      property BorderStyle;
      property CharCase;
      property Color;
      property Constraints;
      property Ctl3D;
      property DragCursor;
      property DragKind;
      property DragMode;
      property Enabled;
      property Font;
      property HideSelection;
      property ImeMode;
      property ImeName;
      property MaxLength;
      property OEMConvert;
      property ParentBiDiMode;
      property ParentColor;
      property ParentCtl3D;
      property ParentFont;
      property ParentShowHint;
      property PasswordChar;
      property PopupMenu;
      property ReadOnly;
      property ShowHint;
      property TabOrder;
      property TabStop;
      property Text;
      property Visible;
      property OnChange;
      property OnClick;
      property OnContextPopup;
      property OnDblClick;
      property OnDragDrop;
      property OnDragOver;
      property OnEndDock;
      property OnEndDrag;
      property OnEnter;
      property OnExit;
      property OnKeyDown;
      property OnKeyPress;
      property OnKeyUp;
      property OnMouseDown;
      property OnMouseMove;
      property OnMouseUp;
      property OnStartDock;
      property OnStartDrag;
  end;

  procedure Register;
 
implementation

function MinimizeStr(s: String; ACanvas: TCanvas; MaxWidth: integer): string;
var li,ri, tw: integer;
    sLeft, sRight: string;
begin
  if ACanvas.TextWidth(s) < MaxWidth then
  begin
    result:= s;
    Exit;
  end;

  sLeft:= ''; sRight:= '';
  tw:= 0;//ACanvas.TextWidth(s);
  li:= 1; ri:= length(s);
  if ri > 0 then result:= s[1]+'...';
  while (tw < MaxWidth) AND (li < ri) do
  begin
    sleft:= sLeft+ s[li];
    if (ri > li) then sRight:= s[ri] + sRight;
    Inc(li); Dec(ri);

    tw:= ACanvas.TextWidth(sLeft + '...'+sRight);
    if tw < MaxWidth
      then result:= sLeft + '...'+sRight;
  end;
end;

{ TMyEdit }

constructor TMyEdit.Create(AOwner: TComponent);
begin
  inherited;
  FCanvas:= TControlCanvas.Create;
  TControlCanvas(FCanvas).Control:= self;
end;

destructor TMyEdit.Destroy;
begin
  FCanvas.Free;
  inherited;
end;

procedure TMyEdit.WMPaint(var Message: TWMPaint);
var DisplayText: string;
begin
  inherited;
  DisplayText:= MinimizeStr(Text, Canvas, Width);
  Canvas.TextOut(1,1, DisplayText);
end;

procedure Register;
begin
  //you can change Paul below to whatever page tab you would like the component on
  RegisterComponents('Paul', [TMyEdit]);
end;

end.
0
 

Author Comment

by:PeterdeB
ID: 17914748
This is soo coool!! Thank you PierreC!!

Kind regards,

Paul ;-)
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 17915969
Glad to help.
0
 

Author Comment

by:PeterdeB
ID: 17916759
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 ;-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now