Arsip

Archive for Maret, 2008

Download Tips&Trik Code

Maret 26, 2008 Tinggalkan komentar

Code

Iklan
Kategori:Delphi

Trimming all instances of a string from a string

Maret 26, 2008 Tinggalkan komentar

This function is the same as TrimAllChar(), but removes all instances of a string from a string. Read the comment for the usage. Thanks to Jay ejp@ramss.com for this code.function TrimAllStr(const S: string; const Target : string): string;
{ func to remove instances of a string (Target) from a string (S). }
{ e.g. TrimAllStr(‘ABthis ABis ABa ABtest’, ‘AB’) will return ‘this is a test’. }
{ Thanks to Jay <ejp@ramss.com> for this code. }

var
P: integer;
begin
Result := S;
  repeat
P := Pos(Target, Result);
    if P > 0 then
System.Delete(Result, P, Length(Target));
  until
(P = 0);
end;

Kategori:Delphi

Showing the properties of a file

Maret 26, 2008 Tinggalkan komentar

To show the file property dialog commonly used in Windows, call the ShowFileProperties() procedure below passing the filename:uses ShellAPI;

procedure ShowFileProperties(const FileName: string);
{ Displays the Properties dialog for a file or directory. }
{ Thanks to Peter Below (TeamB) <100113.1101@compuserve.com> }
{ for this code. }

var
sei: TShellExecuteInfo;
begin
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.lpFile := PChar(FileName);
sei.lpVerb := ‘properties’;
sei.fMask := SEE_MASK_INVOKEIDLIST;
ShellExecuteEx(@sei);
end;

Kategori:Delphi

Showing the network drive mappings

Maret 26, 2008 Tinggalkan komentar

To show a list of all mapped network drives, use the GetNetworkDriveMappings() function.  Example usage: GetNetworkDriveMappings(Memo1.Lines);function GetNetworkDriveMappings(SList: TStrings): integer;
{ Get a list of mapped network drives (if any). }
{ Code adapted from ZieglerSoft [http://www.zieglersoft.dk/uk.html] }

var
I: Char;
ThePath: string;
MaxNetPathLen: DWord;
begin
SList.Clear;
MaxNetPathLen := MAX_PATH;
SetLength(ThePath, MAX_PATH);
for I := ‘A’ to ‘Z’ do
if WNetGetConnection(PChar(” + I + ‘:’), PChar(ThePath),
MaxNetPathLen) = NO_ERROR then
SList.Add(I + ‘: ‘ + ThePath);
Result := SList.Count;
end;

Kategori:Delphi

Shortening the pathname with an ellipses (…)

Maret 26, 2008 Tinggalkan komentar

I found this function somewhere that I find very useful sometimes.  Pass a long pathname to the function and a handle to the control the path is to be viewed in and it will return the shortened version with an ellipses (…).  The control’s handle is used to determine the width needed for the pathname and will work on any size the system’s font settings are set to. For example, put a TPanel on a form, call the function like this: Panel1.Caption := MinimizePathName(Panel1.Handle, ‘C:\This Directory\This Subdirectory\Another\ThisFile.txt’); and what you will see is ‘C:\…\Another\ThisFile.txt’. Baca selanjutnya…

Kategori:Delphi

Setting the wallpaper (tiled, centered, stretched, or positioned)

Maret 26, 2008 Tinggalkan komentar

This function will set a BMP of your choice as the wallpaper for Windows and you can set it as tiled, stretched, centered, or positioned anywhere on screen. Works on all 32-bit Windows platforms. This procedure should now work with the Active Desktop option turned on. Baca selanjutnya…

Kategori:Delphi

Setting the modified date of a file

Maret 26, 2008 Tinggalkan komentar

Sometimes you want to set your files’ modified dates before shipping the final product to your customers, much like Borland does for the date/time stamps of the BDE files and Delphi binary files.  Read the comment below to see how to use it.procedure SetModifyDate(fName, fDate: string);
{ Proc to modify the Modify Date of a file.                            }
{ Usage: SetModifyDate(‘C:\Temp\SomeFile.txt’, ’12/31/1998 00:00:00′); }
var
  Age,
  FHandle: integer;
  LocalFileTime,
  FileTime: TFileTime;
  FileBuf: file;
begin
  if FileExists(fName) then
    begin
      AssignFile(FileBuf, fName);
      Reset(FileBuf);
      try
        Age := DateTimeToFileDate(StrToDateTime(fDate));
        FHandle := TFileRec(FileBuf).Handle;
        DosDateTimeToFileTime(LongRec(Age).Hi, LongRec(Age).Lo, LocalFileTime);
        LocalFileTimeToFileTime(LocalFileTime, FileTime);
        // to set the files’ last modified date
        SetFileTime(FHandle, nil, nil, @FileTime);
        // to set the files’ created date
        SetFileTime(FHandle, @FileTime, nil, nil);
        // to set the files’ last accessed date
        SetFileTime(FHandle, nil, @FileTime, nil);
      finally
        CloseFile(FileBuf);
     end;
    end
  else
    MessageDlg(‘File does not exist: ‘ + fName, mtError, [mbOK], 0);
end;

Kategori:Delphi