320x100

[Delphi] 3항 연산자, IfThen

Posted on 2016. 4. 28. 14:33
Filed Under Delphi

If문으로 여러줄 작성해야할 코드를 1줄로 작성할 수 있는 매력적인 연산자~!
기본형태: IfThen(비교문, True리턴값, False리컨값)
총 4가지 오버로드 형태가 있음.
// 1-3) Math
function IfThen(AValue: Boolean; const ATrue: Integer; 
                     const AFalse: Integer = $0): Integer; overload;
function IfThen(AValue: Boolean; const ATrue: Int64; 
                     const AFalse: Int64 = $0): Int64; overload;
function IfThen(AValue: Boolean; const ATrue: Double; 
                     const AFalse: Double = 0): Double; overload;

// 4) StrUtils
    function IfThen(AValue: Boolean; const ATrue: string; 
                   AFalse: string = ''): string; overload;
}




반응형

[Delphi] 예외처리 구분 경우 (try/except/finally)

Posted on 2014. 2. 12. 17:50
Filed Under Delphi


Application.MessageBox(PChar('시작'), '정보', MB_ICONINFORMATION);


// try문 외부에서 예외발생 경우
raise Exception.Create('예외경우 발생!'); // 아래 finally 구문 미실행 + Exit()

// try문 외부에서 Exit()할 경우
if 조건 then Exit(); // 아래 try..finally와 관계 없이 종료

try
  try
      ...
      raise Exception.Create('예외발생!'); // except + finally + next 을 모두 수행
      Exit(); // except + finally + next 을 모두 수행(=Exception.Create 와 함께 사용할 필요없는 구문)
      ...
  except
      on e: Exception do
      begin
         // 예외 발생시에만 수행 - finally + next 수행
         Application.MessageBox(PChar(e.Message), PChar('에러'), MB_ICONERROR + MB_OK);
          Exit(); // finally 까지 수행하고 종료 (next 미수행)
      end;
   end;
finally
   // 예외 발생 여부 및 try구문 내의 Exit() 유무에 상관없이 무조건 수행되는 구문
   FreeAndNill(obj);
end;

Application.MessageBox(PChar('next'), PChar('next'), MB_ICONERROR + MB_OK);




반응형

[Delphi] 변수, 상수, 배열, 포인터 Syntax

Posted on 2014. 2. 4. 18:14
Filed Under Delphi


// 문자형 초기화
var
	ch: Char;
begin
	ch := #0;

// 상수값 정의
const
	_FORM01_DEFAULT_CAPTION = '창 제목';
	_MAX_FILESIZE  = 1000000;

// 배열의 인덱스용으로써 타입 정의
type
	TDbActionType = (datSelect, datInsert, datUpdate datDelete, datNone);
const
	_DBACTTYPE_FIRST = 0; // datSelect
	_DBACTTYPE_LAST = datDelete;

// 레코드 타입 정의 및 초기화
type
	TDbActionInfo =  record
		rsQuery: String;
		rsErrorMsg: String;
	end;

const
	DbActionInfoArray: array [_DBACTTYPE_FIRST.._DBACTTYPE_LAST] of TDbActionInfo =
	(
		rsQuery: 'SELECT A FROM tbl_nm WHERE '; rsErrorMsg: 'No Message'),
		rsQuery: 'INSERT INTO tbl_nm VALUES('; rsErrorMsg: 'No Message'),
		rsQuery: 'UPDATE tbl_nm SET'; rsErrorMsg: 'No Message'),
		rsQuery: 'DELETE FROM tbl_nm WHERE'; rsErrorMsg: 'No Message')
	);

// 포인터 정의 (val^ : 값 / @val: 포인터)
var
	val1, val2: TDbActionInfo;
	FPcxImageList: array[0..1] of ^TDbActionInfo;
begin
	FPcxImageList[0] := @val1;
	FPcxImageList[1] := @val2;

	...

	if FPcxImageList[0]^.rsErrorMsg <> 'No Message' then
	begin
		Application.MessageBox(FPcxImageList[0]^.rsErrorMsg, MB_OK + MB_ICONERROR);
	end

반응형

[Delphi] 레코드형 배열 초기화

Posted on 2014. 1. 29. 15:39
Filed Under Delphi

출처: http://www.delmadang.com/community/bbs_view.asp?bbsNo=3&indx=195652(델마당/강좌, 팁, 정보)

type
TFreq = packed record
mFreq: integer;
mDeviation: integer;
end;

TState = packed record
mTime: integer;
mDeviation: integer;
end;

TTone = packed record
mBuf : pChar;
mTid: integer;
mFreq1: TFreq;
mOff: TState;
end;

var
szTone : array [0..2] of TTone
= ((mBuf: nil; mTid: -1; mFreq1:(mFreq: 300; mDeviation: 10); mOff:(mTime: 0; mDeviation: 30)),
(mBuf: nil; mTid: -1; mFreq1:(mFreq: 300; mDeviation: 10); mOff:(mTime: 0; mDeviation: 30)),
(mBuf: nil; mTid: -1; mFreq1:(mFreq: 300; mDeviation: 10); mOff:(mTime: 0; mDeviation: 30)));

Tone : TTone
= (mBuf: nil; mTid: -1; mFreq1:(mFreq: 300; mDeviation: 10); mOff:(mTime: 0; mDeviation: 30));
반응형

[Delphi2010] VCL 기본 클래스 계층도(VCL Hierarchy)

Posted on 2013. 11. 27. 10:17
Filed Under Delphi

VCL(Visual Component Library)는 윈도우프로그래밍을 편리하게 할 수 있도록 델파이에서 제공하는 클래스.

▼ VCL의 기본 클래스(모든 VCL 클래스가 상속받는 클래스)



반응형

About

by 쑤기c

반응형