BLOG main image
분류 전체보기 (65)
JSP (6)
Android (1)
ASP.NET (0)
MSSQL (4)
PHP (18)
ASP (11)
오픈 API (1)
HTML (2)
JavaScript (0)
Windows Programming (8)
컴퓨터교양 (14)
객체 지향 (0)
리뷰 및 생각 (0)
Visitors up to today!
Today hit, Yesterday hit
daisy rss
tistory 티스토리 가입하기!
2010. 9. 13. 02:51

ShellExecute()는 윈도우쉘 명령을 실행시킬 때 쓰는 함수이다.
내가 사용하는 용도는 두가지이다.
한가지는 탐색기를 열 때(지정한 폴더로 이동시키는 것 까지),
나머지 한가지는 파일(윈도우즈 확장자 연결 프로그램으로 등록된 확장자를 가진 파일)을 열 때 이다.

먼저 탐색기를 여는 방법이다.
ShellExecute(0, 'explore', PChar(descDir), nil, nil, SW_SHOWNORMAL);

다음으로 파일을 열 때 이다.
var
  fileFullPath : String;
  errCode : Cardinal;

begin
    errCode := ShellExecute(handle, 'open', Pchar(fileFullPath) , nil, nil, SW_SHOW);
    if errCode = 31 then ShowMessage('HWP가 설치되어 있지 않습니다'); //실행화일 없을때
    if errCode = 2 then ShowMessage('파일이 존재하지 않습니다');      //파일 없을때
end;
2010. 9. 13. 02:33

델파이는 조회 결과레코드셋에 들어 있는 바이너리를
CreateBlobStream() 함수를 이용하여 받을 수 있다.
기본적으로 stream으로 받아서 메모리에 올린 후 원하는 작업을 하면 된다.

이 코드 조각에서는 바이너리를 파일로 저장하기 위해 TMemoryStream의 SaveToFile() 프로시져를 사용하였다.

var
  code, tempFullPath: string;
  stream : TStream;
  blob : string;
  mStream : TMemoryStream;

begin
    with ADOQuery1 do begin
      if Active then Close;
      SQL.Clear;
      SQL.Text := 'SELECT binary'
                + ' FROM tablename'
                + ' WHERE code=:code';
      Parameters.ParamByName('code').Value := code;
      // 여기서 Open의 결과는 한행만을 반환한다.
      Open;
      stream := CreateBlobStream(FieldByName('binary'), bmRead);
      SetLength(blob, stream.Size);
      stream.Read(Pointer(blob)^, stream.Size);
      mStream := TMemoryStream.Create;
      mStream.Write(Pointer(blob)^, Length(blob));
      mStream.SaveToFile(tempFullPath);
    end;
end;
2010. 9. 13. 02:25

보통 ADOQuery를 사용하여 많은 조회 쿼리를 수행한다.
아래는 ADOQuery를 사용할 때 쓰이는 기본적인 코드 조각이다.

  with ADOQuery1 do begin
    if Active then Close;
    SQL.Clear;
    SQL.Text := 'SELECT * FROM tablename';
                   + ' WHERE name = :NAME;
    Parameters.ParamByName('NAME').Value := 'ojh';
    Open;
    while not Eof do begin
      // FieldByName('title').AsString;
      // FieldByName('id').AsInteger;
      Next;
    end;
    Close;
  end;