A
download MiscUtils.pas
Language: Delphi
LOC: 139
Project Info
Maguma Open Studio(openstudio)
Server: SourceForge
Type: cvs
...tudio\OpenStudio\src\Units\
   .cvsignore
   dlgCancel.dfm
   dlgCancel.pas
   DosRedirect.pas
   MiscUtils.pas
   Passwords.pas
   PHPCodeElement.pas
   PHPCodeParser.pas
   PHPDocCommentParser.pas
   PHPUtils.pas
   RedirectConsole.pas
   RegExpr.pas
   ServiceControl.pas
   StringUtils.pas
   ToolButtons.pas

unit MiscUtils;

interface

uses StdCtrls, ComCtrls, Controls, Graphics, Classes, Types;

Type
  TBrowseFolderOption = (bfBrowseForComputer,bfBrowseForPrinter,bfDontGoBelowDomain,
                         bfReturnFileSystemAncestors,bfReturnOnlyFileSystemDirs );
  TBrowseFolderOptions = set of TBrowseFolderOption;

  function BrowseForFolder(var Path: String; const TitleText: String;
      fDisplayOptions : TBrowseFolderOptions) : Boolean;
  procedure DisableEdit(Edit: TEdit);
  procedure EnableEdit(Edit: TEdit);

  function FindTreeNodeByCaption(FirstNode: TTreeNode; sText: String; Data: Pointer): TTreeNode;

  procedure ExpandRect(var rec: TRect; const exptop, expleft, expright, expbottom: Integer);

  function KeyComp(const aKey: String; Temp: PChar): Boolean;

  function Min(a, b: Integer): Integer;
  function Max(a, b: Integer): Integer;

implementation

uses Windows, Messages, ShlObj, SysUtils;

//  Compares aKey (String) with a PChar, only the first Length(aKey) characters
//  Note: AKey must (!!) be LowerCase, KeyComp is Case Sensitive then!
function KeyComp(const aKey: String; Temp: PChar): Boolean;
var
  I, len: Integer;
begin
  Result := True;
  len := Length(aKey);
  for i := 1 to len do
  begin
    if (Temp^ <> aKey[i]) and (Temp^ <> (UpperCase(aKey[i]))) then
    begin
      Result := False;
      break;
    end;
    inc(Temp);
  end;
end; { KeyComp }

function BrowseForFolder(var Path: String; const TitleText: String;
    fDisplayOptions : TBrowseFolderOptions) : Boolean;
Const
  BrowseOptions : array[TBrowseFolderOption] of Integer = ( BIF_BROWSEFORCOMPUTER,
                      BIF_BROWSEFORPRINTER,
                      BIF_DONTGOBELOWDOMAIN,
                      BIF_RETURNFSANCESTORS,
                      BIF_RETURNONLYFSDIRS );
Var
  MyBrowseFolder : TBrowseInfoA;
  pDisplayNameString : PChar;
  BrowseFolderOptions : TBrowseFolderOption;
  Flags : Integer;
  pMyItemList     : PItemIdList;
Begin
  Result := False;
  Try
    Getmem(pDisplayNameString,MAX_PATH);
  Except
    Begin
      MessageBox(0,'Error in allocating the memory','Error', MB_ICONERROR or MB_OK);
      Exit;
    End;
  End;
  Flags := 0;
  for BrowseFolderOptions := Low(BrowseFolderOptions) to High(BrowseFolderOptions) do
    if (BrowseFolderOptions in fDisplayOptions) then
      Flags := Flags or BrowseOptions[BrowseFolderOptions];
  With MyBrowseFolder Do
  Begin
    pidlRoot:=Nil;
    iImage := 0;
    lpszTitle := pchar(TitleText);
    pszDisplayName := pDisplayNameString;
    lpfn := Nil;
    ulFlags  := Flags;
    hwndOwner :=  0;
    lParam := 0;
  End;
  pMyItemList := SHBrowseForFolder( MyBrowseFolder );
  Path := StrPas(pDisplayNameString);
  If pMyItemList <> Nil Then
  Begin
    If SHGetPathFromIdList(pMyItemList,pDisplayNameString) = True Then
      Path := StrPas(pDisplayNameString);
    Result := True;
  End
  Else
    Path := '';
  FreeMem(pDisplayNameString,MAX_PATH);
End;

procedure DisableEdit(Edit: TEdit);
begin
  Edit.Color := clBtnFace;
  Edit.Enabled := False;
end;

procedure EnableEdit(Edit: TEdit);
begin
   Edit.Color := clWindow;
   Edit.Enabled := True;
end;

function FindTreeNodeByCaption(FirstNode: TTreeNode; sText: String; Data: Pointer): TTreeNode;
var
  node: TTreeNode;
begin
  Result := nil;
  Node := FirstNode.GetFirstChild;
  while Assigned(Node) do
  begin
    Result := FindTreeNodeByCaption(Node, sText, Data);
    if Assigned(Result) then
      Exit;
    Node := FirstNode.GetNextChild(Node);
  end;

  Node := FirstNode;
  while Assigned(Node) do
  begin
    if (CompareStr(Node.Text, sText) = 0) and (Node.Data = Data) then
    begin
      Result := Node;
      Exit;
    end;
    Node := Node.getNextSibling;
  end;
end;

procedure ExpandRect(var rec: TRect; const exptop, expleft, expright, expbottom: Integer);
begin
  dec(rec.Top, exptop);
  dec(rec.Left, expleft);
  inc(rec.Right, expright);
  inc(rec.Bottom, expbottom);
end;

function Min(a, b: Integer): Integer;
begin
  Result := a;
  if a > b then
    Result := b;
end;

function Max(a, b: Integer): Integer;
begin
  Result := a;
  if a < b then
    Result := b;
end;

end.

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us