Delphi - object pascal IDE
Tutorials
Tips for beginners in Pascal/Delphi programming:
- IMHO it is good practice to make the directory for each program and to keep all the units, drivers or libraries in that directory.
- use "program Manager" to check if all files of the project are in the same directory.
- to add new unit to program save it in program directory, add to project ( use main menu ) , open unit which must use new unit and then click main menu/File/use Unit.
- Delphi program ( project) consists of more then one files, so use "close all", "save all" "open project"
- " I can't create output file". Maybe you run program from cd (it is a read only (:-)) or maybe you have copied files fromcd. Check file properities, remove "read only"
- ~ = Alt+126
- pascal likes US keyboard ( type: "keyb us" in dos
- when You try to run programs from efg, sometimes errors occurs due to diffrent decimal character, so change temporaly your windows settings for decimal character ( efg likes dot for it) and then run the program.
- Delphi is not a language but IDE. So I'm programing in object Pascal for Windows using Borland Delphi IDE.
- Delphi Form = window
- Delphi project = program
- use program specification because there are meny programming languages, OS and so on.
- divide a problem into a single pieces. Solve one problem in one step ( simple program for solving only this problem). Check the solution. Appplay it to the bigger program
- turn off integrated dubugging / OS exception/ Debugger Options/ tools/Main Menu / Delphi 7.o PE
- "You should consider optimizing your program only after you have a working version and only if that version is too slow." from Laboratory in Software Engineering Spring 2003 MIT
- "Runtime error 216 " - maybe you use object not initialized . Use create as in example :
zPlane:=TPlane.Create;
Pascal compilers and IDE:
for Microsoft windows
Delphi 7.0 personal edition. (dcc (Borland Delphi Compiler)
Dev-Pascal
-
-
Tools:
- pas2html by Primoz Gabrijelcic's
pas2html pas_file html_file [Delphi version (numeric)]
-
Tips:
-
when :
uses Graphics, windows;
then you will get an error:
[Error] Unit1.pas(155): Incompatible types: 'tagBITMAP' and 'TBitmap'
------------------
solution ( I dont know why):
uses windows, Graphics;
------------------
Explanations :
"Są 2 typy TBitamp :
Windows.TBitmap
Graphics.TBitmap.
To który jest 'aktywnym" typem zależy od kolejności unitów Windows i Graphics w sekcji "uses".
Typ Windows.TBitmap to THandle, który z kolei jest po prostu 32-bitowym intem." ( Arivald)
Delphi Images by Robert Clemenzi
- How to display 2 bitmaps in one image ? - example program Directory with src code and exe-file
- How to display bitmap larger then image?
- place a scrool Box on the form
- place a image on the scroll box
- procedure TForm1.FormCreate(Sender: TObject);
begin
Image1.Align:=alNone;
Image1.AutoSize:=true;
ScrollBox1.Align:=alClient;
ScrollBox1.AutoSize:=False;
end;
- How to open bitmap and display it in the image?
- place a image on the form
- place the OpenPictureDialog on the form
- place the MainMenu on the form
- create the MaineMenu item ( give the name in the Menu Designer)
- procedure TForm1.openbmpfile1Click(Sender: TObject);
var CurrentFile:string;
begin
if OpenPictureDialog1.Execute
then begin
CurrentFile := OpenPictureDialog1.FileName;
Image1.Picture.LoadFromFile(CurrentFile);
end;
end;
- How to use radio group in dialog form?
- create new form ( dialog form) here: OKBottomDlg
- ( if exist delate bevel)
- { probably add unit to program)
- ad a new unit containing that dialog form to uses clauses of main unit( file/use unit)
- place a radio group on the dialog form
- create the MaineMenu item ( give the name in the Menu Designer)
- procedure TForm1.transformations1Click(Sender: TObject);
begin
// display the dialog form
OKBottomDlg.ShowModal;
if OKBottomDlg.ModalResult=mrOk
then // place the code here
end;
- add radio button to the radio group, using ObjectInspector ( click on Items to see the streing list editor)
- //use radio button,
procedure TOKBottomDlg.OKBtnClick(Sender: TObject);
begin
case OKBottomDlg.RadioGroup1.ItemIndex of
// they are numbered from 0
0:;//place code here
end;
end;
- How to get the name (as a string) of enumerated type variable ?
// add new unit to uses
uses TypInfo;// getEnumName;
// definition of enumerated type
TFunctionType=(TrueColor=0,GrayScale,direct,BlackAndW);
//declaration of variable
var FunctionType:TFunctionType;
str:string;
// usage
str:=getEnumName(typeInfo(TFunctionType),Ord(FunctionType) );
-
How to make a link to www page in delphi
thx to "Johans" johans2@o2.pl
uses shellapi;
Put label1 on a form
In onClick of Label1 write:
ShellExecute(Handle, 'open','http://ardes url' , nil, nil, SW_SHOWNORMAL);
In onMouseEnter of label1
label1.Cursor:=crHandPoint;
label1.font.Color:=clBlue;
In onMouseLeave of label1 write
label1.Font.Color:=clBlack;
-
// Define 256 shades of gray pf8it palette
var NewPalette: TMaxLogPalette;
//
//in the body of procedure write:
NewPalette.palVersion := $0300; // "Magic Number" for Windows LogPalette
NewPalette.palNumEntries := 256;
//
FOR i := 0 TO 255 DO
BEGIN
NewPalette.palPalEntry[i].peRed := i;
NewPalette.palPalEntry[i].peGreen := i;
NewPalette.palPalEntry[i].peBlue := i;
NewPalette.palPalEntry[i].peFlags := PC_NOCOLLAPSE;
END;
//
Bitmapa.Palette := CreatePalette(pLogPalette(@NewPalette)^);
-
How to count time of execution of procedure:
uses windows; // GetTickCount
var start, time:integer
begin
// start counting
start:=GetTickCount;
// here is place for time consuming code
//stop counting and compute time of execution of procedure
Time:=GetTickCount-Start;
// display time
Form1.Caption:=FloatToStrF(time,ffNumber,10,0);
end;
-
Dynamic arrays
All dynamic arrays starts at index = 0. (from delphibasics by Neil Moffatt )
use:
type TPrimeFactors= Array of integer;
var PrimeFactors: TPrimeFactors;
// if you want to set length of dynamic array inside the procedure:
procedure FindPrimeFactors(var _PrimeFactors: TPrimeFactors);
begin
SetLength(_PrimeFactors,20);
...
-
Strings and arrays
Strings are indexed with 1 for the first character
index of dynamic array starts form 0
Main Page
Feel free to e-mail me!
Author: Adam Majewski adammaj1-at-o2-dot-pl
About
http://republika.pl/fraktal/