Delphi Tip

Programming/Delphi 2012.04.13 10:41 Posted by 파란크리스마스

출처

http://rainflys.tistory.com/84
http://www.borlandforum.com/impboard/impboard.dll?action=read&db=del_qna&no=3570
http://bloodguy.tistory.com/entry/Delphi-바탕화면-시작메뉴프로그램-등-특수-디렉토리-가져오기

현재 실행 폴더 구하기

runpath:=ExtractFilePath(Application.ExeName);

Memo 스크롤 마지막으로 이동

procedure TForm1.Memo1Change(Sender: TObject);
begin
  Memo1.Perform(EM_LINESCROLL, 0, Memo1.Lines.Count);
end;

Format

 format('%0.10d',[10])

시스템 폴더 조회

// 시작 메뉴\프로그램 (C:\Documents and Settings\USER_NAME\시작 메뉴\프로그램)
SHGetFolderPath(0, CSIDL_PROGRAMS, 0, 0, PathPrograms);   
 
// 바탕 화면 (C:\Documents and Settings\USER_NAME\바탕 화면)
SHGetFolderPath(0, CSIDL_DESKTOP, 0, 0, PathDesktop);
unit Winapi.ShlObj;

  CSIDL_DESKTOP                 = $0000;          // 바탕화명 <desktop>
  CSIDL_INTERNET                = $0001;          // Internet Explorer (icon on desktop)
  CSIDL_PROGRAMS                = $0002;          //  시작메뉴\프로그램 Start Menu\Programs
  CSIDL_CONTROLS                = $0003;          // My Computer\Control Panel
  CSIDL_PRINTERS                = $0004;          // My Computer\Printers
  CSIDL_PERSONAL                = $0005;          // My Documents
  CSIDL_FAVORITES               = $0006;          // <user name>\Favorites
  CSIDL_STARTUP                 = $0007;          // Start Menu\Programs\Startup
  CSIDL_RECENT                  = $0008;          // <user name>\Recent
  CSIDL_SENDTO                  = $0009;          // <user name>\SendTo
  CSIDL_BITBUCKET               = $000a;          // <desktop>\Recycle Bin
  CSIDL_STARTMENU               = $000b;          // <user name>\Start Menu
  CSIDL_MYDOCUMENTS             = CSIDL_PERSONAL; // Personal was just a silly name for My Documents
  CSIDL_MYMUSIC                 = $000d;          // "My Music" folder
  CSIDL_MYVIDEO                 = $000e;          // "My Videos" folder
  CSIDL_DESKTOPDIRECTORY        = $0010;          // <user name>\Desktop
  CSIDL_DRIVES                  = $0011;          // My Computer
  CSIDL_NETWORK                 = $0012;          // Network Neighborhood (My Network Places)
  CSIDL_NETHOOD                 = $0013;          // <user name>\nethood
  CSIDL_FONTS                   = $0014;          // windows\fonts
  CSIDL_TEMPLATES               = $0015;

  CSIDL_COMMON_STARTMENU        = $0016;          // All Users\Start Menu
  CSIDL_COMMON_PROGRAMS         = $0017;          // All Users\Start Menu\Programs
  CSIDL_COMMON_STARTUP          = $0018;          // All Users\Startup
  CSIDL_COMMON_DESKTOPDIRECTORY = $0019;          // All Users\Desktop
  CSIDL_APPDATA                 = $001a;          // <user name>\Application Data
  CSIDL_PRINTHOOD               = $001b;          // <user name>\PrintHood
  CSIDL_LOCAL_APPDATA           = $001c;          // <user name>\Local Settings\Applicaiton Data (non roaming)
  CSIDL_ALTSTARTUP              = $001d;          // non localized startup
  CSIDL_COMMON_ALTSTARTUP       = $001e;          // non localized common startup
  CSIDL_COMMON_FAVORITES        = $001f;
  CSIDL_INTERNET_CACHE          = $0020;
  CSIDL_COOKIES                 = $0021;
  CSIDL_HISTORY                 = $0022;
  CSIDL_COMMON_APPDATA          = $0023;          // All Users\Application Data
  CSIDL_WINDOWS                 = $0024;          // GetWindowsDirectory()
  CSIDL_SYSTEM                  = $0025;          // GetSystemDirectory()
  CSIDL_PROGRAM_FILES           = $0026;          // C:\Program Files
  CSIDL_MYPICTURES              = $0027;          // C:\Program Files\My Pictures
  CSIDL_PROFILE                 = $0028;          // USERPROFILE
  CSIDL_SYSTEMX86               = $0029;          // x86 system directory on RISC
  CSIDL_PROGRAM_FILESX86        = $002a;          // x86 C:\Program Files on RISC
  CSIDL_PROGRAM_FILES_COMMON    = $002b;          // C:\Program Files\Common
  CSIDL_PROGRAM_FILES_COMMONX86 = $002c;          // x86 Program Files\Common on RISC
  CSIDL_COMMON_TEMPLATES        = $002d;          // All Users\Templates
  CSIDL_COMMON_DOCUMENTS        = $002e;          // All Users\Documents
  CSIDL_COMMON_ADMINTOOLS       = $002f;          // All Users\Start Menu\Programs\Administrative Tools
  CSIDL_ADMINTOOLS              = $0030;          // <user name>\Start Menu\Programs\Administrative Tools
  CSIDL_CONNECTIONS             = $0031;          // Network and Dial-up Connections
  CSIDL_COMMON_MUSIC            = $0035;          // All Users\My Music
  CSIDL_COMMON_PICTURES         = $0036;          // All Users\My Pictures
  CSIDL_COMMON_VIDEO            = $0037;          // All Users\My Video
  CSIDL_RESOURCES               = $0038;          // Resource Direcotry
  CSIDL_RESOURCES_LOCALIZED     = $0039;          // Localized Resource Direcotry
  CSIDL_COMMON_OEM_LINKS        = $003a;          // Links to All Users OEM specific apps
  CSIDL_CDBURN_AREA             = $003b;          // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning

  // unused                               0x003c
  CSIDL_COMPUTERSNEARME         = $003d;          // Computers Near Me (computered from Workgroup membership)
  CSIDL_FLAG_CREATE             = $8000;          // combine with CSIDL_ value to force folder creation in SHGetFolderPath()
  CSIDL_FLAG_DONT_VERIFY        = $4000;          // combine with CSIDL_ value to return an unverified folder path
  CSIDL_FLAG_DONT_UNEXPAND      = $2000;          // combine with CSIDL_ value to avoid unexpanding environment variables
  CSIDL_FLAG_NO_ALIAS           = $1000;          // combine with CSIDL_ value to insure non-alias versions of the pidl
  CSIDL_FLAG_PER_USER_INIT      = $0800;          // combine with CSIDL_ value to indicate per-user init (eg. upgrade)
  CSIDL_FLAG_MASK               = $FF00;          // mask for all possible flag values

파일 경로 얻어오기

path := ExtractFilePath(Application.exeName);

- end -

신고

Delphi tip - 시스템 임시 폴더 구하기

Programming/Delphi 2011.02.19 14:22 Posted by 파란크리스마스
출처 : http://www.delphitricks.com/source-code/systeminfo/get_windows_system_temporary_directory.html

{ Getting the Temporary Directory } 

function GetTempDir: string; 
var 
  Buffer: array[0..MAX_PATH] of Char; 
begin 
  GetTempPath(SizeOf(Buffer) - 1, Buffer); 
  Result := StrPas(Buffer); 
end; 

function GetTempPath: string; 
var 
  TmpDir: PChar; 
begin 
  TmpDir := StrAlloc(MAX_PATH); 
  GetTempPath(TmpDir, MAX_PATH); 
  Result := string(TmpDir); 
  if Result[Length(Result)] <> '\' then 
    Result := Result + '\'; 
  StrDispose(TmpDir); 
end; 

function GetTempPath(var S: String): Boolean; 
var 
  Len: Integer; 
begin 
  Len := Windows.GetTempPath(0, nil); 
  if Len > 0 then 
  begin 
    SetLength(S, Len); 
    Len := Windows.GetTempPath(Len, PChar(S)); 
    SetLength(S, Len); 
    Result := Len > 0; 
  end else 
    Result := False; 
end; 
신고

Delphi - TcxVirtualTreeList

Programming/Delphi 2010.12.05 00:49 Posted by 파란크리스마스
- CustomDataSource 사용시 동적인 Count 사용
OptionsData.SmartLoad := True;

- 트리노드의 초기 + 표시
OptionsData.CheckHasChildren := false;
신고

Delphi - Drag & Drop

Programming/Delphi 2010.11.10 21:39 Posted by 파란크리스마스
출처 : http://kjs1981.tistory.com/entry/%EB%8D%B8%ED%8C%8C%EC%9D%B4-Drag-Drop%EC%9D%98-%EC%A0%95%EB%A6%AC-%ED%8E%8C-softech%EA%B3%A8%EB%B1%85%EC%9D%B4pppkornet21net

1. 소스 : cxVirtualTreeList1.DragMode = dmAutomatic

DragMode = dmAutomatic의 경우 모든 객체에 대해서 Darg 모드가 적용되지만
특정객체만 선택적으로 Drag 모드가 적용되게 하려면 DragMode = dmManual 로 수정하고
MouseDown 이벤트에서 BeginDrag(False); 로 해준다.

cxVirtualTreeList1.DragMode = dmManual  // 수정

procedure TObjectTreeForm.cxVirtualTreeList1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  TableItem : TTableItem;
begin
  TableItem := DBManager.DBObjectTreeModel.DoSelectNode(cxVirtualTreeList1.GetNodeAt(x, y));
  if Assigned(TableItem) then begin
    cxVirtualTreeList1.BeginDrag(False);  { 있다면 드랙을 시작한다. }
    ColumnGridModel.ColumnList := TableItem.ColumnList;
    ColumnGridModel.DataChanged;
  end;
end;

2. 대상 : OnDragOver 이벤트

procedure TfrmSQLEditor.SyntaxMemo1DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
var
  TableItem : TTableItem;
begin
  if (Source is TcxVirtualTreeList) then begin
    TableItem := DBManager.DBObjectTreeModel.DoSelectNode((Source as TcxVirtualTreeList).DragNode);
    if Assigned(TableItem) then begin
      Accept := true;
    end;
  end;
end;

3. 대상 : DragDrop이벤트

procedure TfrmSQLEditor.SyntaxMemo1DragDrop(Sender, Source: TObject; X,
  Y: Integer);
var
  TableItem : TTableItem;
begin
  if (Source is TcxVirtualTreeList) then begin
    TableItem := DBManager.DBObjectTreeModel.DoSelectNode((Source as TcxVirtualTreeList).DragNode);
    if Assigned(TableItem) then begin
      SyntaxMemo1.InsertText(TableItem.Name);
    end;
  end;
end;

신고

Delphi Tip - 숫자 여부 확인

Programming/Delphi 2010.05.18 17:52 Posted by 파란크리스마스
Delphi에서 StrToInt을 하는 경우 Exception 발생하는데, Debug 시에는 귀찮을 때가 있어
Tip을 올립니다.

SysUtil.pas의 StrToInt 내부를 보면,
Var 함수를 사용하고 있는데, 3번째 인자의 값이 0이 아니면 Exception을 발생하도록 되어 있습니다.

function StrToInt(const S: string): Integer;
var
  E: Integer;
begin
  Val(S, Result, E);
  if E <> 0 then ConvertErrorFmt(@SInvalidInteger, [S]);
end;

사용예)
아래의 예를 보시면 Result 값을 0으로 초기화 하고
Var의 3번째 인자의 값이 0이면 Result에 값에 담아서 반환하도록 했습니다.

function StrToInt2(const S: string): Integer;
var
  intTemp, E : Integer;
begin
  Result := 0;
  // 숫자 여부 확인
  Val(S, intTemp , E);
  if E=0 then
    Result := intTemp ;
end
신고

Delphi Tip - 디렉토리 문자열 분리

Programming/Delphi 2010.04.04 06:31 Posted by 파란크리스마스


uses
  StrUtils;

procedure TForm1.Button1Click(Sender: TObject);
var
  tmpDirStr : String;
  offset : integer;

  function GetFindStr(SubFindStr : String; var offset : integer):string;
  var
    offsetOld, offset2 : integer;
  begin
    Result := '';

    offset2 := 0;
    if SubFindStr[offset] = '/' then
      inc(offset2);

    offsetOld := offset;
    offset := PosEx('/', SubFindStr, offset + offset2);

    if offset>0 then begin
      Result := MidStr(SubFindStr, offsetOld + offset2, offset-offsetOld-offset2);
    end;
  end;

begin
  tmpDirStr := Edit1.Text;

  if (tmpDirStr[Length(tmpDirStr)]<>'/') then
    tmpDirStr := tmpDirStr + '/';

  offset := 1;

  while (offset > 0) do begin
    Memo1.Lines.Add(GetFindStr(tmpDirStr, offset));
  end;
end;

신고

Delphi Tip 로케일(Locale) 확인 하기

Programming/Delphi 2010.01.20 10:48 Posted by 파란크리스마스

원본 사이트 : http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10231553.html

procedure TForm1.Button1Click(Sender: TObject);

  function GetLocale(ALcid: Integer): string;
  var s: string;
  begin
    Result := '[Unknown]';
    SetLength(s, 128);
    if GetLocaleInfo(ALcid, LOCALE_SENGLANGUAGE, PChar(s), 128) > 0 then
      begin
        Result := StrPas(PChar(s));
        if GetLocaleInfo(ALcid, LOCALE_SENGCOUNTRY, PChar(s), 128) > 0 then
          begin
            Result := Format('%s (%s)', [Result, StrPas(PChar(s))]);
          end;
      end;
  end;

begin
  showmessage(GetLocale(GetUserDefaultLangID));
end;

더보기


 

신고

[Delphi] TTreeNode.Data

Programming/Delphi 2009.05.01 10:11 Posted by 파란크리스마스
출처 : http://users.iafrica.com/d/da/dart/zen/Articles/TTreeView/TTreeView_eg05.html

-- end --
신고

Delphi Tip - GetSystemPath

Programming/Delphi 2009.04.11 18:50 Posted by 파란크리스마스
출처 : http://www.scalabium.com/faq/dct0106.htm
http://delphi.mylivepage.com/wiki/1380/638

uses
  ShlObj, ActiveX;

function GetSystemPath(Folder: Integer): string;
var
  PIDL: PItemIDList;
  Path: LPSTR;
  AMalloc: IMalloc;
begin
  Path := StrAlloc(MAX_PATH);
  SHGetSpecialFolderLocation(Application.Handle, Folder, PIDL);
  if SHGetPathFromIDList(PIDL, Path) then
    Result := Path;
  SHGetMalloc(AMalloc);
  AMalloc.Free(PIDL);
  StrDispose(Path);
end;

-----------------------------------------------------------------------

typedef enum {
 CSIDL_DESKTOP = 0x0000,
 CSIDL_INTERNET = 0x0001,
 CSIDL_PROGRAMS = 0x0002,
 CSIDL_CONTROLS = 0x0003,
 CSIDL_PRINTERS = 0x0004,
 CSIDL_PERSONAL = 0x0005,
 CSIDL_FAVORITES = 0x0006,
 CSIDL_STARTUP = 0x0007,
 CSIDL_RECENT = 0x0008,
 CSIDL_SENDTO = 0x0009,
 CSIDL_BITBUCKET = 0x000A,
 CSIDL_STARTMENU = 0x000B,
 CSIDL_MYDOCUMENTS = 0x000C,
 CSIDL_MYMUSIC = 0x000D,
 CSIDL_MYVIDEO = 0x000E,
 CSIDL_DESKTOPDIRECTORY = 0x0010,
 CSIDL_DRIVES = 0x0011,
 CSIDL_NETWORK = 0x0012,
 CSIDL_NETHOOD = 0x0013,
 CSIDL_FONTS = 0x0014,
 CSIDL_TEMPLATES = 0x0015,
 CSIDL_COMMON_STARTMENU = 0x016,
 CSIDL_COMMON_PROGRAMS = 0x0017,
 CSIDL_COMMON_STARTUP = 0x0018,
 CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019,
 CSIDL_APPDATA = 0x001A,
 CSIDL_PRINTHOOD = 0x001B,
 CSIDL_LOCAL_APPDATA = 0x001C,
 CSIDL_ALTSTARTUP = 0x001D,
 CSIDL_COMMON_ALTSTARTUP = 0x001E,
 CSIDL_COMMON_FAVORITES = 0x001F,
 CSIDL_INTERNET_CACHE = 0x0020,
 CSIDL_COOKIES = 0x0021,
 CSIDL_HISTORY = 0x0022,
 CSIDL_COMMON_APPDATA = 0x0023,
 CSIDL_WINDOWS = 0x0024,
 CSIDL_SYSTEM = 0x0025,
 CSIDL_PROGRAM_FILES = 0x0026,
 CSIDL_MYPICTURES = 0x0027,
 CSIDL_PROFILE = 0x0028,
 CSIDL_SYSTEMX86 = 0x0029,
 CSIDL_PROGRAM_FILESX86 = 0x002A,
 CSIDL_PROGRAM_FILES_COMMON = 0x002B,
 CSIDL_PROGRAM_FILES_COMMONX86 = 0x002C,
 CSIDL_COMMON_TEMPLATES = 0x002D,
 CSIDL_COMMON_DOCUMENTS = 0x002E,
 CSIDL_COMMON_ADMINTOOLS = 0x002F,
 CSIDL_ADMINTOOLS = 0x0030,
 CSIDL_CONNECTIONS = 0x0031,
 CSIDL_COMMON_MUSIC = 0x0035,
 CSIDL_COMMON_PICTURES = 0x0036,
 CSIDL_COMMON_VIDEO = 0x0037,
 CSIDL_RESOURCES = 0x0038,
 CSIDL_RESOURCES_LOCALIZED = 0x0039,
 CSIDL_COMMON_OEM_LINKS = 0x003A,
 CSIDL_CDBURN_AREA = 0x003B,
 CSIDL_COMPUTERSNEARME = 0x003D,
 CSIDL_FLAG_PER_USER_INIT = 0x0800,
 CSIDL_FLAG_NO_ALIAS = 0x1000,
 CSIDL_FLAG_DONT_VERIFY = 0x4000,
 CSIDL_FLAG_CREATE = 0x8000,
 CSIDL_FLAG_MASK = 0xFF00
} CSIDL Values;

Constants

CSIDL_DESKTOP Windows desktop-virtual folder that is the root of the name space. 
CSIDL_INTERNET Virtual folder that represents the Internet. 
CSIDL_PROGRAMS File system directory that contains the user's program groups (which are also file system directories). A typical path is C:\Documents and Settings\username\Start Menu\Programs. 
CSIDL_CONTROLS Virtual folder that contains icons for Control Panel applications. 
CSIDL_PRINTERS Virtual folder that contains installed printers. 
CSIDL_PERSONAL File system directory that serves as a common repository for documents. A typical path is C:\Documents and Settings\username\My Documents. This is different from the My Documents virtual folder in the name space. To access that virtual folder, use the technique described in Managing the File System . 
CSIDL_FAVORITES File system directory that serves as a common repository for the user's favorite items. A typical path is C:\Documents and Settings\username\Favorites. 
CSIDL_STARTUP File system directory that corresponds to the user's Startup program group. The system starts these programs whenever any user logs onto Microsoft® Windows NT® or starts Microsoft Windows® 98. A typical path is C:\Documents and Settings\username\Start Menu\Programs\Startup. 
CSIDL_RECENT File system directory that contains the user's most recently used documents. A typical path is C:\Documents and Settings\username\Recent. To create a shortcut in this folder, use SHAddToRecentDocs . In addition to creating the shortcut, this function updates the Shell's list of recent documents and adds the shortcut to the Documents submenu of the Start menu. 
CSIDL_SENDTO File system directory that contains Send To menu items. A typical path is C:\Documents and Settings\username\SendTo. 
CSIDL_BITBUCKET Virtual folder that contains the objects in the user's Recycle Bin. 
CSIDL_STARTMENU File system directory that contains Start Menu items. A typical path is C:\Documents and Settings\username\Start Menu. 
CSIDL_MYDOCUMENTS Virtual folder that contains the objects in the user's My Documents folder.
CSIDL_MYMUSIC File system directory that serves as a common repository for music files. A typical path is C:\My Music. 
CSIDL_MYVIDEO File system directory that serves as a common repository for video files. 
CSIDL_DESKTOPDIRECTORY File system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself). A typical path is C:\Documents and Settings\username\Desktop 
CSIDL_DRIVES My Computer-virtual folder that contains everything on the local computer: storage devices, printers, and Control Panel. The folder can also contain mapped network drives. 
CSIDL_NETWORK Network Neighborhood-virtual folder that represents the root of the network namespace hierarchy. 
CSIDL_NETHOOD A file system folder that contains the link objects that can exist in the My Network Places virtual folder. It is not the same as CSIDL , which represents the network namespace root. A typical path is C:\Documents and Settings\username\NetHood. 
CSIDL_FONTS Virtual folder that contains fonts. A typical path is C:\WINNT\Fonts. 
CSIDL_TEMPLATES File system directory that serves as a common repository for document templates. 
CSIDL_COMMON_STARTMENU File system directory that contains the programs and folders that appear on the Start Menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. Valid only for Windows NT systems. 
CSIDL_COMMON_PROGRAMS File system directory that contains the directories for the common program groups that appear in the Start Menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs. Valid only for Windows NT systems. 
CSIDL_COMMON_STARTUP File system directory that contains the programs that appear in the Startup folder for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Valid only for Windows NT systems. 
CSIDL_COMMON_DESKTOPDIRECTORY File system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop. Valid only for Windows NT systems. 
CSIDL_APPDATA Version 4.71 . File system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\username\Application Data. This CSIDL is supported by the redistributable ShFolder.dll for systems that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed. 
CSIDL_PRINTHOOD File system directory that contains the link objects that can exist in the Printers virtual folder. A typical path is C:\Documents and Settings\username\PrintHood. 
CSIDL_LOCAL_APPDATA Version 5.0 . File system directory that serves as a data repository for local (nonroaming) applications. A typical path is C:\Documents and Settings\username\Local Settings\Application Data. 
CSIDL_ALTSTARTUP File system directory that corresponds to the user's nonlocalized Startup program group. 
CSIDL_COMMON_ALTSTARTUP File system directory that corresponds to the nonlocalized Startup program group for all users. Valid only for Windows NT systems. 
CSIDL_COMMON_FAVORITES File system directory that serves as a common repository for all user's favorite items. Valid only for Windows NT systems. 
CSIDL_INTERNET_CACHE Version 4.72 . File system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\username\Temporary Internet Files. 
CSIDL_COOKIES File system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\username\Cookies. 
CSIDL_HISTORY File system directory that serves as a common repository for Internet history items. 
CSIDL_COMMON_APPDATA Version 5.0 . Application data for all users. A typical path is C:\Documents and Settings\All Users\Application Data. 
CSIDL_WINDOWS Version 5.0 . Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\WINNT. 
CSIDL_SYSTEM Version 5.0 . System folder. A typical path is C:\WINNT\SYSTEM32. 
CSIDL_PROGRAM_FILES Version 5.0 . Program Files folder. A typical path is C:\Program Files. 
CSIDL_MYPICTURES Version 5.0 . My Pictures folder. A typical path is C:\Documents and Settings\username\My Documents\My Pictures. 
CSIDL_PROFILE Version 5.0 . User's profile folder. 
CSIDL_SYSTEMX86 The x86 system directory on Reduced Instruction Set Computer (RISC) systems. 
CSIDL_PROGRAM_FILESX86 The x86 Program Files folder on RISC systems. 
CSIDL_PROGRAM_FILES_COMMON Version 5.0 . A folder for components that are shared across applications. A typical path is C:\Program Files\Common. Valid only for Windows NT and Windows 2000 systems. 
CSIDL_PROGRAM_FILES_COMMONX86 The x86 Program Files Common folder on RISC systems. 
CSIDL_COMMON_TEMPLATES File system directory that contains the templates that are available to all users. A typical path is C:\Documents and Settings\All Users\Templates. Valid only for Windows NT systems. 
CSIDL_COMMON_DOCUMENTS File system directory that contains documents that are common to all users. Typical paths are C:\Documents and Settings\All Users\Documents. Valid for Windows NT systems and Windows 95 and Windows 98 systems with Shfolder.dll installed. 
CSIDL_COMMON_ADMINTOOLS Version 5.0 . File system directory that contains administrative tools for all users. 
CSIDL_ADMINTOOLS Version 5.0 . File system directory used to store administrative tools for an individual user. The Microsoft Management Console (MMC) saves customized consoles to this directory, and it roams with the user. 
CSIDL_CONNECTIONS Virtual folder that contains network and dial-up connections. 
CSIDL_COMMON_MUSIC My Music folder for all users. For more information, see CSIDL . 
CSIDL_COMMON_PICTURES My Pictures folder for all users. For more information, see CSIDL . 
CSIDL_COMMON_VIDEO My Video folder for all users. For more information, see CSIDL . 
CSIDL_RESOURCES System resource directory. A typical path is C:\WINNT\Resources. 
CSIDL_RESOURCES_LOCALIZED Localized resource directory. For more information, see CSIDL . 
CSIDL_COMMON_OEM_LINKS Folder containing links to OEM specific applications for all users. 
CSIDL_CDBURN_AREA File system folder used to hold data for burning to a CD. Typically [User Profile Folder]\Local Settings\Applications Data\Microsoft\CD Burning. 
CSIDL_COMPUTERSNEARME Computers Near Me folder. Virtual folder that contains links to nearby computers on the network. Nearness it is established by common work group membership. 
CSIDL_FLAG_PER_USER_INIT Combine this flag with the desired CSIDL_ value to indicate per-user initialization. 
CSIDL_FLAG_NO_ALIAS Combine this flag with the desired CSIDL_ value to force a non-alias version of the PIDL. 
CSIDL_FLAG_DONT_VERIFY Combine this flag with the desired CSIDL_ value to return an unverified folder path. 
CSIDL_FLAG_CREATE Combine this flag with the desired CSIDL_ value to force the creation of the associated folder. 
CSIDL_FLAG_MASK Mask for all possible CSIDL flag values. 

Enumerated Type Information
Minimum operating systems Windows 95, Windows NT 4.0, Windows XP

See Also
SHGetFolderLocation, SHGetFolderPath, SHGetSpecialFolderLocation, SHGetSpecialFolderPath

신고

Delphi Tip - 파일이름 관련 함수

Programming/Delphi 2008.03.04 17:27 Posted by 파란크리스마스
Delphi Tip - 파일이름 관련 함수

출처 : http://delphi.borlandforum.com/impboard/impboard.dll?action=read&db=del_tip&no=179
http://www.swissdelphicenter.ch/torry/showcode.php?id=144
http://www.delphibasics.co.uk/RTL.asp?Name=StringReplace

// 델파이
function ExtractFileDir(const FileName: string): string;
function ExtractFileDrive(const FileName: string): string;
function ExtractFileName(const FileName: string): string;
function ExtractFilePath(const FileName: string): string;

예)

filename := ExtractFileName(  StringReplace(url, '/', '\', [rfReplaceAll, rfIgnoreCase]) );
신고

Delphi - File Download

Programming/Delphi 2008.03.04 12:58 Posted by 파란크리스마스

Delphi Tip - File Download

출처 : http://delphi.about.com/od/internetintranet/a/get_file_net.htm

uses WinInet;

function GetInetFile (const fileURL, FileName: String): boolean;
const
  BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of Byte;
  BufferLen: DWORD;
  f: File;
  sAppName: string;
begin
  result := false;
  sAppName := ExtractFileName(Application.ExeName);
  hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0) ;
  try
    hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0) ;
    try
      AssignFile(f, FileName);
      Rewrite(f,1) ;
      repeat
        InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
        BlockWrite(f, Buffer, BufferLen);
      until BufferLen = 0;
      CloseFile(f) ;
      result := True;
    finally
      InternetCloseHandle(hURL);
    end
  finally
    InternetCloseHandle(hSession);
  end;
end;

// 윈도우즈의 임시폴더 명을 반환한다.
function SysTempPath(): String;
var
  Buffer: array[0..1023] of Char;
begin
  SetString(Result, Buffer, GetTempPath(Sizeof(Buffer)-1, Buffer));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  internetFile,
  localFileName: string;
begin
 internetFile := 'http://localhost:8080/Sample.jmd';
 localFileName := SysTempPath() + 'test.xml';

 if GetInetFile(internetFile, localFileName) then
   ShowMessage(SysTempPath() + 'Sample.jmd' + ' / Download successful.')
 else
   ShowMessage('Error in file download.') ;
end;

신고


 

티스토리 툴바