Wikia

Delphi Programming

JEDI Code Library

2,918pages on
this wiki
Talk0

The JEDI Code Library (JCL) contains lots of useful functions and classes. It is maintained as an open source project (Mozilla public license) by the Project JEDI team on SourceForge. The code quality is quite high even though it lacks a bit on the documentation side.

The JCL contains only bare units, containing classes and helper functions/procedures. There are no components in the JCL. For lots of free components, see the sister project, JEDI_Visual_Component_Library. The JCL and JVCL both have separate installer routines, launched by running the install.bat batch file. The command line delphi compiler is used to build and install the JCL. You can not install this package while the Delphi IDE is running on your computer. Shut down Delphi, install this, then start up delphi again.

For example, one of the frequently asked questions: "How can I determine the name of the current procedure or method?" can be solved using the JCL like this:

unit u_JclDebugTest;

interface

function CurrentFunctionName: string;

type
  TSomeClass = class
  private
  public
    constructor Create;
    destructor Destroy; override;
    procedure Test;
  end;

implementation

uses
  JclDebug;

{ TSomeClass }

constructor TSomeClass.Create;
begin
  WriteLn(CurrentFunctionName);
end;

destructor TSomeClass.Destroy;
begin
  WriteLn(CurrentFunctionName);
  inherited;
end;

procedure TSomeClass.Test;
begin
  WriteLn(CurrentFunctionName);
end;

{$W+}

function CurrentFunctionName: string;
begin
  Result := jcldebug.GetLocationInfoStr(Caller(1));
end;

end.


program jcldebugtest;

{$APPTYPE console}

uses
  u_JclDebugTest;

procedure SomeProcedure;
begin
  WriteLn(CurrentFunctionName);
  with TSomeClass.Create do begin
    Test;
    Free;
  end;
end;

begin
  WriteLn(CurrentFunctionName);
  SomeProcedure;
  WriteLn(CurrentFunctionName);
end.

This program will output:

[0042362D] jcldebugtest.jcldebugtest (Line 18, "jcldebugtest.dpr")
[004223A7] jcldebugtest.SomeProcedure (Line 10, "jcldebugtest.dpr")
[0042226C] u_JclDebugTest.TSomeClass.Create (Line 34, "u_JclDebugTest.pas")
[00422352] u_JclDebugTest.TSomeClass.Test (Line 45, "u_JclDebugTest.pas")
[004222E5] u_JclDebugTest.TSomeClass.Destroy (Line 39, "u_JclDebugTest.pas")
[00423651] jcldebugtest.jcldebugtest (Line 20, "jcldebugtest.dpr")

Note that this functionality needs either the program's .map file or the jcl-debug information for looking up the names. Also note, that this lookup takes quite a few processor cycles.

JclDebug contains lots of other functions useful for debugging, like:

  • TraceMsg - writes a message to the debug log
  • TraceFmt - writes a message + parameters to the debug log
  • TraceLoc - writes a message + the current function / method to the debug log
  • TraceLocFmt - write a message + parameters + the current function / method to the debug log

External Links Edit

Around Wikia's network

Random Wiki