Rad Studio 2009 에서 Delphi .NET 으로 Compact Framework 기반 프로그램 만들기


Setting up the Development Environment

Installing the Compact Framework Assemblies

.NET Compact Framework 2.0 SDK 를 설치해야 한다.
파일명은 netcfsetupv2.msi 이고 기본 설치 경로는 \Program Files\Microsoft.NET\SDK\CompactFramework\v2.0 다.

다운로드 경로는 아래와 같다.
http://www.microsoft.com/downloads/details.aspx?familyid=AEA55F2F-07B5-4A8C-8A44-B4E1B196D5C0&displaylang=en

이하 SDK 설치가 되어있는 상태로 가정하고 설명한다.


Creating Borland.Delphi.System.dcuil

.NET CF 에 맞는 .dcuil 파일을 생성해야 한다.

dccil --clrversion=v2.0.70450 -DCF -m -q -nsBorland.VclCF
-nsBorland.Vcl -ln"C:\Program Files (x86)\CodeGear\RAD Studio\6.0\lib\CF"
-W-UNIT_PLATFORM -W-SYMBOL_PLATFORM
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\mscorlib.dll"
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.dll"
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.Xml.dll"
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.Drawing.dll"
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.Windows.Forms.dll"
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.Data.dll"
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.Windows.Forms.DataGrid.dll"
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.Web.Services.dll"
-lu"C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.Net.IrDA.dll"
-N"C:\Program Files (x86)\CodeGear\RAD Studio\6.0\lib\CF"
-U"C:\Program Files (x86)\CodeGear\RAD Studio\6.0\lib\CF"
-LN"C:\Program Files (x86)\CodeGear\RAD Studio\6.0\lib\CF" -z --no-config -Y
- "C:\Program Files (x86)\CodeGear\RAD Studio\6.0\Source\DotNet\rtl\borland.delphi.system.pas"


경로는 본인의 설치 환경에 맞게 수정하고 Rad Studio 아래에 lib\CF 디렉토리는 생성해준다.
나의 경우는 64bit OS를 사용하기때문에 Program Files 경로가 일반적인 32bit 환경과는 다르다.

netcf.bat 파일처럼 dos 용 batch 파일을 만들어서 하는게 편할것 이다.

주의 할 점은 위에 내용을 그대로 복사하면 CRLF가 붙게 되어서 여러줄로 저장이 되는데 CRLF가 없도록 해줘야 한다.
쉽게 말하면 엔터키 없이 한줄로 쭉 적어야 한다.
이렇게 하지 않으면 에러 메세지가 나올것이다.

성공적으로 실행 되었다면 생성해둔 CF 디렉토리에 아래와 같은 파일이 생성 될것이다.

Borland.Delphi.System.dcuil
mscorlib.dcpil
System.Data.dcpil
System.dcpil
System.Drawing.dcpil
System.Net.IrDA.dcpil
System.Web.Services.dcpil
System.Windows.Forms.DataGrid.dcpil
System.Windows.Forms.dcpil
System.Xml.dcpil



Configuring the Emulator

다운로드 경로는 아래와 같다.
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=38c46aa8-1dd7-426f-a913-4f370a65a582

0412/Windows Mobile 6 Professional Images (KOR).msi 다운로드 한 후 설치한다.

설치후 시작->프로그램->Windows Mobile 6 SDK->Standalone Emulator Images->Korean->Professional 선택해서 실행하면 아래와 같은 화면이 나온다.



File->Configure... 메뉴를 선택해서 Share folder 를 선택해준다.
이곳은 Emulator 에서 메모리 카드 슬롯 처럼 작동하는 곳으로 컴파일된 프로그램을 테스트 할때 유용하다.

나는 아래와 같이 설정했다.




Creating a Compilation Batch File

이제 CF 프로그램 생성시 사용할 batch file 을 만들어 보자.

내용은 아래와 같다.

@echo off
rem **************************************************************
rem ** Batch file to be used from the RAD Studio 2007 IDE Tools
rem ** menu to invoke the Delphi for .NET compiler to compile
rem ** Compact Framework applications. It takes two parameters
rem ** as follows:
rem **  %1 - Name of project .dpr file
rem **  %2 - Path to project directory
rem **************************************************************

set _DCCILPATH_="C:\Program Files (x86)\CodeGear\RAD Studio\6.0\Bin\dccil.exe"
set _CFUNITS_="C:\Program Files (x86)\CodeGear\RAD Studio\6.0\lib\CF"
set _PROJECTNAME_=%1
set _PROJECTDIR_=%2
set _OUTPUTDIR_="D:\dev\Delphi.NET\CF\Shared"

rem *************************************************************
rem ** Ensure the RAD Studio 2007 Bin directory is in the path.
rem ** It may have been removed by a User path override.
rem *************************************************************
set _BDSDIR_=C:\Program Files (x86)\CodeGear\RAD Studio\6.0\Bin
path %_BDSDIR_%;%PATH%

rem *************************************************************
rem ** Cater for the fact that paths with spaces can't be passed
rem ** in from the Tools menu
rem *************************************************************
SHIFT
SHIFT
:LOOP
IF "%1" == "" GOTO END
set _PROJECTDIR_=%_PROJECTDIR_% %1
SHIFT
GOTO LOOP
:END

rem *************************************************************
rem ** Change to the project drive and directory
rem *************************************************************
FOR /F "tokens=1 delims=\ " %%A IN ('echo %_PROJECTDIR_%') DO SET _DRIVE_=%%~dA
%_DRIVE_%
cd %_PROJECTDIR_%
del *.dc?il

%_DCCILPATH_% -DCF --no-config "%_PROJECTDIR_%%_PROJECTNAME_%" -u%_CFUNITS_% -luSystem.Windows.Forms -luSystem.Data -E%_OUTPUTDIR_%
pause

자신의 설정에 맞게 디렉토리는 적절하게 변경한다.

각 옵션은 이 글의 마지막에 원문 글의 링크를 적어둘테니 참고 바란다.

파일은 아까 만들어둔 경로에 저장한다.

나의 경우는 아래와 같다.
D:\dev\Delphi.NET\CF\CFBuild.bat

위의 Batch File 을 IDE에 연결 시켜보자.

IDE 를 실행시키고 Tools 메뉴를 선택하고 Configure Tools... 를 선택하고 Add 버튼을 누른다.
창에 아래와 같이 입력한다.
Title : Delphi .NET CF Compiler
Program : D:\dev\Delphi.NET\CF\CFBuild.bat
Parameters : $SAVEALL $NAMEONLY($PROJECT).dpr $PATH($PROJECT)





Developing and Running a Delphi for .NET Application

Creating the Project

RadStudio 를 실행 하고 File->New->Other… 선택후
Delphi for .NET Projects 선택하고 Console Application 선택한다.
파일명은 HelloWorld.dproj 로 한다.


The Project Source

새 unit 을 추가하고 이름은 MainForm.pas 로 하자.
소스는 아래와 같다.

unit MainForm;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms;

type
  TMainForm = class(System.Windows.Forms.Form)
  strict private
    Components: System.ComponentModel.Container;
    Label1: System.Windows.Forms.Label;
    Button1: System.Windows.Forms.Button;
    Label2: System.Windows.Forms.Label;
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
  strict protected
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;

implementation

{$AUTOBOX ON}

procedure TMainForm.InitializeComponent;
begin
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  //
  // Label1
  //
  Self.Label1.Location := System.Drawing.Point.Create(16, 16);
  Self.Label1.Text := 'Hello World!';
  //
  // Button1
  //
  Self.Button1.Location := System.Drawing.Point.Create(16, 40);
  Self.Button1.Text := 'Click Me!';
  Include(Self.Button1.Click, Self.Button1_Click);
  //
  // Label2
  //
  Self.Label2.Location := System.Drawing.Point.Create(16, 72);
  Self.Label2.Size := System.Drawing.Size.Create(152, 23);
  //
  // TMainForm
  //
  Self.ClientSize := System.Drawing.Size.Create(292, 266);
  Self.Controls.Add(Self.Label2);
  Self.Controls.Add(Self.Button1);
  Self.Controls.Add(Self.Label1);
  Self.MinimizeBox := False;
end;

procedure TMainForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TMainForm.Create;
begin
  inherited Create;
  InitializeComponent;
end;

procedure TMainForm.Button1_Click(sender: System.Object; e: System.EventArgs);
begin
  Label2.Text := 'Delphi is in the building!';
end;

end.



Project->View Source 한뒤 .dpr 파일은 아래와 같이 만든다.

program HelloWorld;

uses
  System.Windows.Forms,
  MainForm in 'MainForm.pas';

begin
  Application.Run(TMainForm.Create);
end.



Compiling the Project

아래 메뉴를 선택해서 컴파일 하자.



실행하면 아래와 같은 창이 뜬다.



에러가 나지만 걱정할건 없다.

Batch File에 설정한 D:\dev\Delphi.NET\CF\Shared\ 디렉토리에 들어가보면
HelloWorld.exe 파일이 만들어 진것을 확인할수 있다.

Emulator 에서 확인해보자.



위와 같이 정상 작동 함을 확인 할 수 있다.



한글 출력도 정상적으로 되는걸 확인 할 수 있다.


영문 출처 : http://edn.embarcadero.com/article/37915#37915_tocentry1

키란디아

내 인생의 목표는 내가 하고 싶은, 좋아하는, 원하는 일만 하며 언제나 행복감을 느끼면서 사는 것이다.

댓글 쓰기

다음 이전