• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

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 >

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

These are my kind regards!!

Paul :)
0
PeterdeB
Asked:
PeterdeB
  • 4
  • 3
1 Solution
 
Pierre CorneliusCommented:
Was your question not answered in the other link?
0
 
Pierre CorneliusCommented:
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
 
PeterdeBAuthor Commented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Pierre CorneliusCommented:
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
 
PeterdeBAuthor Commented:
This is soo coool!! Thank you PierreC!!

Kind regards,

Paul ;-)
0
 
Pierre CorneliusCommented:
Glad to help.
0
 
PeterdeBAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now