728x90

출처

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 -

728x90
728x90
TClientDataset 데이터를 XML로 가지고 왔지만,
일본어에 표현에 문제가 발견 되었다.

모든 문자열 데이터의 경우 fieldtype="string"로 사용했는데,
유니코드의 경우 fieldtype="string.uni" 라고
표현해야 TWideStringField로 인식하여 올바르게 데이터가 표현되지만,
영문만 있는경우 또 다시 문제가 발견되었다.

영문만 존재하는 경우 데이터를 모두 확인하여 fieldtype="string"로 했지만,
이것도 임시 방편일뿐 완벽한 처리는 되는 않는다.

TClientDataset 자체의 버그라고 생각되지만, 우선은 이렇게 처리 해두었다.

------------------------------------------------------------------------
FastReport 에도 다국어를 위해서 처리 해야 하는 문제가 발견되었다.
TfrxMemoView 속성에서 UseDefaultCharset 값을 True로 해야 일본어가 올바르게 표시 되었다.

관련 소스 위치

procedure TfrxCustomMemoView.GetData;
var
  i, j: Integer;
  s, s1, s2, dc1, dc2: WideString;
  ThLocale: Cardinal;
  LocCharset: Boolean;
begin
  inherited;
  ThLocale := 0;
  LocCharset := ((Font.Charset <> DEFAULT_CHARSET) and  not FUseDefaultCharset);
  if IsDataField then
  begin
    if DataSet.IsBlobField(DataField) then
    begin
      if LocCharset then
      begin
        ThLocale := GetThreadLocale;
        SetThreadLocale(GetLocalByCharSet(Font.Charset));
      end;
        DataSet.AssignBlobTo(DataField, FMemo);
      if LocCharset then
        SetThreadLocale(ThLocale);
    end
    else
    begin
      FValue := DataSet.Value[DataField];
      if FDisplayFormat.Kind = fkText then
      begin
        if LocCharset then
          FMemo.Text := AnsiToUnicode(AnsiString(DataSet.DisplayText[DataField]), Font.Charset)
     else

       FMemo.Text := DataSet.DisplayText[DataField];

      end
      else FMemo.Text := FormatData(FValue);
      if FHideZeros and (TVarData(FValue).VType <> varString) and
      {$IFDEF Delphi12}(TVarData(FValue).VType <> varUString) and{$ENDIF}
        (TVarData(FValue).VType <> varOleStr) and (FValue = 0) then
        FMemo.Text := '';
    end;
  end
728x90
728x90
행추가
ws.InsertRows(row+1, 1);

행삭제
ws.DeleteRows(row, row+4);

셀병합
ws.MergeCells(1, p_row, 1, row-1);

테두리     
ws.Range.ItemsRef['A'+inttostr(2)+':'+'A'+inttostr(row)].BorderOutlineStyle := cbsThin; // cbsHair;

가운데 설정
ws.Cell[9, row].HorizAlignment := chaCenter;

몇 가지 설정
ws.Cell[i, row].NumberFormat := '_-* #,##0_-;-* #,##0_-;_-* ""-""_-;_-@_-';
ws.Cell[9, row].NumberFormat := '0%';

셀높이 설정
ws.Rows[(i*28)+2].Height := ws.Rows[2].Height;

셀복사
XLS01.CopyCells(SheetIndex, 0,0,7,27, SheetIndex, 0,(i*28));

출력 설정
XLS01.Sheet[SheetIndex].PrintSettings.Options := [psoHorizCenter];
XLS01.Sheet[SheetIndex].PrintSettings.HorizPagebreaks.Clear;
//
HorizPagebreak := ws.PrintSettings.HorizPagebreaks.Add;
HorizPagebreak.Row := (loopRow*28)+addRow-tmpAddRow-1;

배경색 지정

function RGBToColor(R,G,B:Byte): TColor;
begin
Result:=B Shl 16 Or
G Shl 8 Or
R;
end;

color := RGBToColor(255,255,0)
ws.Range.ItemsRef['A'+IntToStr(row)+':'+GetRowStr(col)+IntToStr(row)].FillPatternForeColor := TColorToClosestXColor(color);
728x90
728x90
출처 : 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; 
728x90
728x90
- CustomDataSource 사용시 동적인 Count 사용
OptionsData.SmartLoad := True;

- 트리노드의 초기 + 표시
OptionsData.CheckHasChildren := false;
728x90
728x90
출처 : 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;

728x90
728x90



Delphi 2010으로 컴파일,
MeCab 라이브러리 사용

일본어 검색엔진이나 번역기를 만들기 위해
일본어 형태소 단위로 분석하는 프로그램입니다.

일본어 문장을 입력하고 [실행]하시면,
단어, 조사, 동사 등으로 분리하여 결과를 보여줍니다.

한자로 된 단어의 읽는 방법이나
동사의 기본형도 나오니 공부하는데 도움이 될까 싶어 올립니다.

728x90
728x90
출처 : http://stackoverflow.com/questions/728701/what-is-the-send-api-for-accessing-menu-commands-from-outside-application
http://swissdelphicenter.com/torry/showcode.php?id=1104
http://www.delphisources.ru/pages/faq/base/get_res_names.html
http://www.swissdelphicenter.ch/torry/showcode.php?id=1710

// Grab sub menu for a Window (by handle), given by (0 based) indices in menu hierarchy
function GetASubmenu(const hW: HWND; const MenuInts: array of Integer): HMENU;
var
  hSubMenu: HMENU;
  I: Integer;
begin
  Result := 0;
  if Length(MenuInts) = 0 then
    Exit;
 
  hSubMenu := GetMenu(hW);
  if not IsMenu(hSubMenu) then
    Exit;
 
  for I in MenuInts do
  begin
    Assert(I < GetMenuItemCount(hSubMenu), format('GetASubmenu: tried %d out of %d items',[I, GetMenuItemCount(hSubMenu)]));
    hSubMenu := GetSubMenu(hSubMenu, I);
    if not IsMenu(hSubMenu) then
      Exit;
  end;
 
  Result := hSubMenu;
end;
 
// Get the caption for MenuItem ID
function GetMenuItemCaption(const hSubMenu: HMENU; const Id: Integer): string;
var
  MenuItemInfo: TMenuItemInfo;
begin
  MenuItemInfo.cbSize := 44;           // Required for Windows 95. not sizeof(AMenuInfo)
  MenuItemInfo.fMask := MIIM_STRING;
  // to get the menu caption, 1023 first chars should be enough
  SetLength(Result, 1023 + 1);
  MenuItemInfo.dwTypeData := PChar(Result);
  MenuItemInfo.cch := Length(Result)-1;
  if not GetMenuItemInfo(hSubMenu, Id, False, MenuItemInfo) then
    RaiseLastOSError;
  // real caption's size. Should call GetMenuItemInfo again if was too short
  SetLength(Result, MenuItemInfo.cch);
  {$WARN SYMBOL_PLATFORM OFF}
  if DebugHook > 0 then
    OutputDebugString(MenuItemInfo.dwTypeData);
end;
 
procedure Test;
var
  hwnd, hSubMenu: Cardinal;
  id : Integer;
begin
//  hwnd := FindWindow('Afx:00400000:8:00010013:00000000:03F61829', nil); // UltraEdit
//  hSubMenu := GetASubmenu(hwnd, [5,0]);

  hwnd := FindWindow('Notepad', nil); // get the 1st instance of Notepad...
  hSubMenu := GetASubmenu(hwnd, [3]); // 4th submenu Menu aka &View
 
  if hSubMenu > 0 then
  begin
    id := GetMenuItemID(hSubMenu, 0); // 1st Item in that sub menu (must not be a submenu itself)
    if id > -1 then
    begin
      PostMessage(hwnd, WM_COMMAND, id, 0); 
      ShowMessage('Done: ' + GetMenuItemCaption(hSubMenu, id));
    end
    else
      RaiseLastOSError;
  end
  else
    RaiseLastOSError;
end;

// 리소스 파일에 존재하는 메뉴 조회
procedure GetMenuInfo2(MainMenu: hMenu; MenuType : TMenuType);
var
  id : integer;
  i, nItems: Integer;
  hwnd, hSubMenu: hMenu;
  menuTitle : String;
begin
  nItems := GetMenuItemCount(MainMenu);
  for i := 0 to  nItems - 1 do begin
    id := GetMenuItemID(MainMenu, i);
    if id > -1 then begin
      menuTitle := GetSubMenuItemCaption(MainMenu, id);
      if Length(menuTitle)>0 then begin
        //ShowMessage(menuTitle);
        MenuType.Menus.Add(menuTitle);
      end;
    end else begin
      hSubMenu := GetSubMenu(MainMenu, i );
      GetMenuInfo2(hSubMenu, MenuType);
    end;
  end;
end;
728x90

+ Recent posts