home | applications | components | forms | tips and tricks | tutorials | forum | guestbook | links

 

Small and basic programming tutorials entirely devoted to delphi

 

To be able to see the popups and also to be able to read any win32 help under windows 7 download the following file, for 32 and 64 bit windows 7 all version

 

Download win32hlp for windows 7 32 bit
Download win32hlp for windows 7 64 bit

 

Each and every project contains the finished compiled and uncompiled code, you can freely use it and do not have to code anything but can dive right in...

For the most part I know my way around in delphi and had the most problems in the very beginning since I could not really seem to get useful help from the delphi api ever, and while this has been the standard for its documentation I sometimes found that to be very frustrating, and from that feeling I developed the desire to make it less difficult for other people. This in short is why I started to create the delphi 7 tutorials, they all are easy, short and to the point so you would be able to create a few helpful applications all by yourself without having to buy any component for it. I am a newbie myself too and have had many people who were willing to assist me. But then still the concept is sharing and making it easier for eachother. All software starts its life as freeware but only a handful will become valuable shareware. Having said that, the following projects will enable you to create very cool effects, while using freeware still.

How to write your own Delphi components in less than 3 minutes

 

Tired of repeatedly changing the same values of the same properties of the same components? Here is a way to change all of the components you work with, so they provide you exactly with what you want, saving you time!

When you create a component, you add to the component library by deriving a new class from one of the existing class types in the hierarchy. Every component is a descendant, and the class you are deriving from is the ancestor. Note that there are two libraries which you can use, one for Windows [VCL] and one for Cross Platform [CLX], you can tell the difference by the following example. If you are gonna derive from the class TButton, then for Windows, the ancestor is StdCtrls, while for Crossplatform this is QStdCtrls, notice the Q.

This delphi tutorial was kept as short as possible, since Delphi can be rather overwhelming, and since this is aimed at the beginner and the standard Delphi help does not really provide any conceptual support, this tutorial will give you a quick and easy start into writing [modifying] delphi components.

It was created after I found out that it was rather easy to write [modify] your own components. It is a very basic tutorial, which I hope will help many people, into making the Delphi programming somewhat more efficient. It is however not the only way, but it is the way I use to limit my efforts for repeatetive tasks, if you are into programming, then you know you can always use your time for different tasks than those you know how to and have to perform again and again.

Download the whole project, it provides detailed help, with a very user friendly manual, consisting of 8 steps, in less than 3 minutes!

To give you an idea how easy it can be I have created two examples explaining the basics, they are included in the project, a mirror is provided in case one of the servers is out of order.

Link to this posted article

 

Download Watch Online [limited version]

 

Create a fully featured webbrowser within minutes with added functionality


Chapter 1 - Create a custom progressbar
Chapter 2 - Adding a download current url button
Chapter 3 - Enable copy and paste
Chapter 4 - Adding find feature
Chapter 5 - Adding an edit current page feature
Chapter 6 - Add print features
Chapter 7 - Create a list links feature
Chapter 8 - Are we online?
Chapter 9 - Set the color of the progressbar
Chapter 10 - Place the progressbar over a statusbar
Chapter 11 - Populate statusbar with MAC address
Chapter 12 - Retrieve Network Group Name and show it
Chapter 13 - Display the local IP on the statusbar
Chapter 14 - Fill up the last TPanel with some info
Chapter 15 - Capture screenshot from url
Chapter 16 - Adding navigation

 

Download Creating a customized webbrowser with many added features

How to write your own progress bar in less than a minute

 

Create your own progressive bar! This very short delphi help shows you how to add a progress bar to any web browser programs you make in no time. It is very basic, and kept as short as possible, you can figure out most of the code just by looking at it. Aimed at beginners, this gives you an easy and quick way to have this working feature which informs the user of the progress the web browser is making! You can then focus on the other tasks like for instance the graphical representation to make it the way you want it

 

A follow up tutorial is about to be posted which will include many more features useful while surfing the internet. It will not replace this one but does have the same funtionality plus many extras.

Download Watch Online [limited version]

Build your own splashscreen in delphi

 

This is also a basic and to the point helpfile for how to create your own splash screen in delphi 7. The best way to learn any programming language is to have an example, and study the code. Do not rely on 3rd party components when you do not have to! Create your own splashing screen and following this tutorial, you will learn to create a splash, that can be disabled by un checking a checkbox on the mainform, it makes use of an Inifile to store the value and enable and disable the appearance of the Splashscreen. About the included example, to test it a simple restart button was added to it, in order to make that work Shellapi was added to the uses clausule of Form1. A follow up tutorial can be accessed for creating even more cool effects, if you managed to stay awake;)

Demo Delphi Application included in the download link here.

Download Watch Online

.

Create a splash screen with transparency

 

This is a follow up of the above helpfile, it is recommended to first look at the other tutorial before proceeding with this one which explains you how to create an even more cool splashscreen that is partially transparent

Download Watch Online

 

Autosplash with a progress indicator

 

Note that I finished this one today, so the real tutorial has to be created still but feel free to download the finished files already ofcourse Version 3 of the splashscreen tutorials adds even more features to it, that make any application stand out well. As soon as your program is launched the splash appears, with a tprogressbar on it, with which you can customize whether, or whether not, and also if so which text should be displayed during the three phases of the splashscreen in this project. They are Initialization, creation and finalization. Many properties can be set exactly to suit your needs like delay, sleep, and step ofcourse. A transparent procedure was added which renders the form itself completely invisible while keeping the content visible, this way you do not have to install the pngcomponents if you don't want to, and I have placed a few panels on it which will ofcourse also remain visible.

Download

 

Saving and Restoring Size, state and Position of your form between restarts.

 

Ever wanted to save and restore the size and position of your Tform using Registry or Inifile? For ease of testing I have enclosed a way to easily restart the application by clicking on the form anywhere, to make this happen I had to add Shellapi to the uses clausule. And also, to make the Registry version of this example, I added Registry to the uses clausule and for the Inifile version, I added, you guessed it, TInifiles, a simple but effective delphi tutorial!

Download

 

How do I create a tform in a tform?

 

Scroll down for the complete download of all the code

Three easy examples of how to create a Form in a form, so that the second [and third, fourth etc] is inside the first form. It has an example of a form without a titlebar [bsNone], one with a form that is resizable and movable, plus one that is not resizable and movable. It also includes a template for a starting point should you wanna create a form-in-a-form.


Borderstyles

Note that borderstyle bsDialog presents you with only a close icon normally but if you use that in the Form-in-a-form, it has no effect in the Not_Moveable_Resizable version, it will show up but will not be clickable. Same counts for bsResizable, the icons will show up but will not be clickable You will have to experiment what normal settings do with a form-in-a-form


Movable and Resizable Form-in-a-form

While the code in Unit2.pas makes sure you can move and resize the form you should also note that the BorderStyle of the form2 is set to bsSingle. Since setting this to bsSizeable does not result in the form2 being movable and or resizable, it only gives you the resize cursor when you hover over each of the 4 sides of the form itself, which serves no purpose to me. Also, the Captionbuttons [border icons] were removed, and the position was set to poDefaultPosOnly, plus the scrollbars were removed, these were the settings that differ from the defaults, change it the way you wish.

 

.

Not Movable and Resizable Form-in-a-form

While the code in Unit2.pas makes sure you cannot move and resize the form you should also note that the BorderStyle of the form2 is set to bsSingle. Since setting this to bsSizeable does not result in the form2 being movable and or resizable, it only gives you the resize cursor when you hover over each of the 4 sides of the form itself, which serves no purpose to me. Also, the Captionbuttons [border icons] were removed, and the position was set to poDefaultPosOnly, plus the scrollbars were removed, these were the settings that differ from the defaults, change it the way you wish.

 


No Titlebar Form-in-a-form

The borderstyle of Form2 was set to bsNone, and the position was set to poDefaultPosOnly. A bevel was added to the form2 but this was to make it appear and also it looks nice to me.

 

 


Template Mainform

Just a quick and easy starting point should you wanna create a Form-in-a-form

download

Link to the article online


custom exception handler


Problem/Question/Abstract:

Each project has logical errors or by runtime. It would be fine to write these exceptions down to a file in order to find out, what's happened weeks ago ;) or to track component events

Answer:

Exceptions are mistakes and errors due to some run-time problem. This is obviously a wishy-washy definition, but generally run-time problems would be things like running out of memory whilst adding a data object or an index out of bounds. In our team we wrote a procedure (months ago), which intercepts those nasty things like exceptions by assigning a new event-handler in the main-unit:


{$IFDEF DEBUG}
Application.OnException := AppOnException;
{$ENDIF}


If DEBUG is not set the code runs at full speed, but I advise to set the handler all the time, cause then you can analyse each applications exception file. Normal testing should identify programming mistakes, whereas the other type of error are exceptions to the norm.
The event-handler goes like this:

procedure TCWForm.AppOnException(sender: TObject; E: Exception);
var
  Addr: string[9];
  FErrorLog: System.Text;
  FileNamePath: string;
begin //writes errorlog.txt file
  FileNamePath := extractFilePath(application.exeName) + 'errorlog.txt';
  AssignFile(FErrorLog, FileNamePath);
  try
    System.Append(FErrorlog);
  except
    on EInOutError do
      Rewrite(FErrorLog);
  end;
  Addr := IntToHex(Seg(ErrorAddr), 4) + ';' + IntToHex(Ofs(ErrorAddr), 4);
  Writeln(ErrorLog, format('%s[%s]%s%s', [DateTimeToStr(Now),
    getNetUserName, E.Message, Addr]));
  System.Close(FErrorLog);
  MessageDlg('CW5' + E.Message + '. occured at: ' + Addr, mtError, [mbOK], 0);
end;


To avoid scope conflicts, Assign File replaces the Assign procedure that was available in previous versions of Delphi. The Addr also depends on the OS. Note, that you want still see exceptions on the screen, you get it with the last MessageDlg in the AppOnException-routine.

Then you get an output in a well shaped manner:

*************************ERRORLOG************************************
26.09.99 12:09:16 [MAX] List index out of bounds 52FF;1226
26.09.99 13:05:28 [MAX] Database BezSpr not found 5F6F;1226
26.09.99 13:21:37 [THOMAS] List index out of bounds 69DF;1226
26.09.99 13:43:35 [MAX] GP fault in module CW5.EXE at 0002:3588 2A9F;1226
30.09.99 14:32:23 [SIMON] Cannot perform this operation on a closed dataset 320F;1254
30.09.99 14:35:36 [MAX] Record locked by another user. Table:GBK.DB

Maybe, the function getNetUserName has to be changed, it depends on the operating-system or the database you deal with:


function getNetUserName: string;
var
  szVar: array[0..32] of char;
begin
  DBIGetNetUserName(szVar);
  result := StrPas(@szVar);
end;


Instead of Addr := by an Exception, use in a 32 - bit environment:

mem: TMemoryStatus;
mem.dwLength := sizeOf(TMemoryStatus);
GlobalMemoryStatus(mem);
edit3.text := intToStr((mem.dwAvailPageFile) div 1024);
edit4.text := intToStr((mem.dwAvailPhys) div 1024);

 


Component Event Logger

On the other side you want to know component events to track down user or system behavior. This is also usefull to show the events on runtime in a listbox or to store it in a file.


First your declare a procedure in your class:

events: TListBox;

procedure LogEvent(const EventStr: string; Component: TComponent = nil)


Second you define the procedure with a listbox as events:

procedure TransAct.LogEvent(const EventStr: string;
  Component: TComponent = nil);
var
  ItemCount: Integer;
begin
  if (csDestroying in ComponentState) or not Events.Visible then
    Exit;
  if (Component <> nil) and (Component.Name <> '') then
    Events.Items.Add(Format('%s(%s)', [EventStr, Component.Name]))
  else
    Events.Items.Add(EventStr);
  ItemCount := Events.Items.Count;
  Events.ItemIndex := ItemCount - 1;
  if ItemCount > (Events.ClientHeight div Events.ItemHeight) then
    Events.TopIndex := ItemCount - 1; //tracing
end;


Third you call the procedure LogEvent in your code as you want, e.g.:

LogEvent('OnDataChange', Sender as TComponent);
LogEvent('BeforeOpen', DataSet);
LogEvent('AfterClose', DataSet);

procedure TransAct.DataSetBeforeClose(DataSet: TDataSet);
begin
  LogEvent('BeforeClose');
end;

procedure TransAct.DataSetError(DataSet: TDataSet;
  E: EDatabaseError; var Action: TDataAction);
begin
  LogEvent('OnDelete/OnEdit/OnPost Errors', DataSet);
end;

procedure TransAct.Disconnect(Connection: TADOConnection;
  var EventStatus: TEventStatus);
begin
  LogEvent('Disconnect', Connection);
end;

function TScanner.SaveLogData(const UserData: WideString; const CheckSum: DWORD):
  Boolean;
var
  SL: TStringList;
  FileName: string;
begin
  SL := TStringList.Create;
  FileName :=
    'D:\Scanner\LogData\' + FormatDateTime('yyyymmdd-hhnnsszzz', Now) + '.txt';
  SL.Text := UserData;
  SL.SaveToFile(FileName);
  SL.Free;
  Result := True;
end;
                

 

Download the exception or event log project files here

 

 



Updated: September 02 2011 05:35:09.
Last Download: Feb 23 2012 00:23:50
Pageviews: 81420