본문 바로가기

델파이

[Delphi] class 상속, interface 위임 Delphi에서는 기본적으로 다중 상속을 지원하지 않는다. 다중 상속의 위험성은 너무나도 뻔하기에... 뻔하면서도 중요한 부분이기 때문에 많은 사람들이 그렇게 자세히 설명을 하고 있는 것이다.이는 객체지향을 지향하는 프로그램에서는 공통된 사항이다. 때문에 C#, JAVA도 다중 상속을 허락하지 않는다. 대신 인터페이스를 이용하여 다중 상속(더 분명하게 표현하자면 기능의 위임이라고 하는 것이 좋을 수도 있다)을 지원하고 있다. 그렇다면 다중 상속은 아예 필요하지 않는 것일까? 사람마다 다르겠지만... 난 필요하다고 본다. 다중 상속이 안된다면 논리적으로 불편한 일이 생길 것이다. 실제로 다중 상속을 피해 프로그램을 개발하려고 하다 보면 논리적 구조가 괜히 복잡해지는 경우가 생긴다... 그리고 필요가 없었다.. 더보기
[Delphi] Excel 경로 및 Office 버전 찾기. uses절에 Registry 추가.uses Registry; procedure TForm1.FormCreate(Sender: TObject);begin ShowMessage(GetOfficeVersion(GetExcelPath));end; function TForm1.GetExcelPath: string;var tempRegistry: TRegistry;begin tempRegistry := TRegistry.Create; try tempRegistry.RootKey := HKEY_LOCAL_MACHINE; if tempRegistry.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe', False) then Result := .. 더보기
[Delphi] Excel 변환 FireMonkey Desktop Application으로 프로젝트 생성(VCL Forms Application 생성시에도 동일) uses절에 ComObj, VCL.OleCtrls 추가.Form에 Button, SaveDialog 생성. unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, ComObj, VCL.OleCtrls; const xlBottom = -4107; xlLeft = -4131; xlRight = -4152; xl.. 더보기
[Delphi] Clipboard의 이미지 불러오기 uses절에 Cliipbrd를 추가.uses Clipbrd; procedure TForm1.ClipboardTest;var tempBitmap : TBitmap;begin // 클립보드 이미지의 사이즈 측정 tempBitmap := TBitmap.Create; try tempBitmap.LoadFromClipBoardFormat(CF_BITMAP, Clipboard.GetAsHandle(CF_BITMAP), 0); ShowMessage('Clipboard Image Width : ' + IntToStr(tempBitmap.Width) + #13 + 'Clipboard Image Height : ' + IntToStr(tempBitmap.Height)); finally tempBitmap.free; end.. 더보기
[Delphi] Image파일을 확장자별로 불러오기 Delphi XE3 기준.uses절에 Vcl.Imaging.jpeg, Vcl.Imaging.pngimage, Vcl.Imaging.gifimg 을 추가. 확장자별로 파일 불러오기 procedure. (*.BMP, *.JPEG, *.GIF, *.PNG) procedure TForm1.ImageLoadTest;var tempGraphic : TGraphic; tempFileStream : TFileStream; tempFirstBytes : AnsiString; tempFileName : string;begin tempFileName := '파일명' (Ex : C:\Users\Public\Pictures\Test.jpg); tempFileStream := TFileStream.Create(tempFileNa.. 더보기
[Delphi] 스크린 기준 컴포넌트 객체의 좌표 구하기 * TPoint 를 이용.procedure TfrmTest.TestButtonClick(Sender: TObject);var tempPoint : TPoint;begin tempPoint := TSpeedButton(Sender).ClientToScreen(Point(0, 0)); ShowMessage('[X : ' + IntToStr(tempPoint.X) + '] [Y : ' + IntToStr(tempPoint.Y) + ']');end; 더보기
[Delphi] 레지스트리(Registry) 등록 레지스트리 등록하는 간단한 예제 소스 1. 대충 폼을 그리고 2. 소스 (1) 'TRegistry' Class를 이용하여 myRegistry 선언. (2) myRegistry 의 Rootkey 설정. (3) 사용할 경로의 레지스트리 존재 유무 확인 후 레지스트리 등록 * 추가적으로 'TRegIniFile' Class를 이용하여 ini파일 읽기/쓰기 식으로도 등록 가능하다. unit frmRegiSetup; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Registry; type TForm1 = class(TForm) Button1: TButton; Butto.. 더보기
[Delphi] 재귀함수를 이용한 폴더 복사 재귀를 이용한 폴더 복사pOverWrite 가 True이면 덮어쓰기, False이면 덮어쓰지 않고 건너감// pSourceDir 폴더를 pDestinationDir 경로로 복사// pSourceDir : 소스 디렉토리, pDestinationDir : 목적 디렉토리, pOverWrite : 덮어쓰기 유무procedure CopyDirectoryAll(pSourceDir, pDestinationDir: string; pOverWrite: Boolean);var TempList : TSearchRec;begin if FindFirst(pSourceDir + '\*', faAnyFile, TempList) = 0 then begin if not DirectoryExists(pDestinationDir) the.. 더보기