Showing posts with label Delphi. Show all posts
Showing posts with label Delphi. Show all posts

Tuesday, March 17, 2026

Many years ago I wrote a windows application that could be used to build biochemical models visually. Origially called JDesigner but subsequently renamed to PathwayDesigner. Over the years the code grew larger and somewhat unwieldy. In addition it couldn't run on the Mac. I have decided therefore to rewrite it using more modern tech so that is can run on the Mac as well as Windows. Initially it won't include simulation capabilities since simulators are dime a dozen. It also won't support SBGN or the SBML layout/render standard since htey are hard to support. The GitHub repo can be found here, currenlty at version 0.1.1 https://github.com/hsauro/PathwayDesigner

Tuesday, April 19, 2022

Lorenz Attractor

I wanted to test out Google's skia 2D library so I wrote a simple interactive Lorenz attractor app over the weekend. Source code and binaries at 

https://github.com/hsauro/Lorenz_fmx

Binaries are only for Windows at the moment but hope to have a Mac version in a couple of weeks.

I used Object Pascal to write it but it should be easily translatable to something like C# and WinForms which were modeled after Object Pascal and the VCL. Looks like skia does a better job at antialiasing lines and also it's quite fast.

I use a simple Euler integration scheme to solve the Lorenz ODEs, nothing fancy but it seems to work perfectly well. 




Sunday, January 4, 2015

Simple RK4 Code

January 4, 2015 10:11 pm 

Thought I'd start off the New Year with a simple freebie, a 4th Order Runge-Kutta class for Delphi, Windows and Mac OS. Should also work on Android and iOS mobile platforms and with Free Pascal. The code below shows how you'd use it. First declare the set of differential equations that need to be solved (TDoubleDynArray type can be found in Types):

 TMySystem = class (TObject)
    class procedure func (time : double; y, p, dydt : TDoubleDynArray);
 end;

class procedure TMySystem.func (time : double; y, p, dydt : TDoubleDynArray);
begin
  dydt[0] := p[0] - p[1]*y[0];
  dydt[1] := p[1]*y[0] - p[2]*y[1];
end;

Next, create a Runge-Kutta object:

// First argument = number of ODEs
// Second argument = number of parameters, if any
// Third argument = ODE Function
rk4 := TRK4.Create (2, 3, TMySystem.func);
rk4.p[0] := vo; rk4.p[1] := k1; rk4.p[2] := k2;

The above code include the option to declare and initialize some parameters that are part of the differential equations. To actually integrate the system by one step use the line:

// Return new time point, assign to startTime ready for next time
startTime := rk4.eval (startTime, y, stepSize);

The y argument will contain the updated solution. Run the line again to do the next step etc. Note that the eval method takes three arguments, that current value for the independent variable (time), an array that contains the current values for the dependent variable, and the step size to use.

Download the code here. RK4.zip The download include a Windows exe that you can try right away.

Wednesday, September 19, 2012

The Delphi Color Palette

September 19, 2012 7:30 pm

This is the Delphi color palette, both 'normal' and 'web' colors. The 'normal' colors start with red and end with black. The 'web' colors start at Moccasin. 

See http://docwiki.embarcadero.com/RADStudio/en/Colors_in_VCL) for more information.







Sunday, September 4, 2011

Useful tips for fireMonkey and Delphi XE2

Originally Posted on  by hsauro

Here is a list of useful tips for using fireMonkey.

Update (7 Sept 2011): A report from Embarcadero indicates that Anchor support will eventually be provided in FireMonkey.

1. Fonts too fuzzy? You may find that font rendered in controls such as TMemo or TEdit are a bit fuzzy, particularly on a white background. To improve font quality, follow a suggestion from Jermey North:

This could be due to the Direct 2D canvas. Try the GDI+ plus canvas and see if this makes the fonts clearer.

Before Application.Initialize in the project file, add this line:

FMX.Types.GlobalUseDirect2D := False;

You need to put FMX.Types and FMX.Canvas.GDIP in the uses clause as
well.

Works for me. Update 12 Sept: For an even better solution see tip #11.

2. Qualified Font Styles. From Jon Souter, can’t get this to compile?

CheckBox1.Font.Style:=[fsBold];
Label1.Font.Style:=[fsBold];

Use this instead (from Jeremy North and Chris Rolliston):

CheckBox1.Font.Style:=[TFontStyle.fsBold];
Label1.Font.Style:=[TFontStyle.fsBold];

Styles must now be qualified.

3. Font Size Differences: In VCL, font sizes are specified using points, eg 10 point, that is 72 points per inch. In fireMonkey font sizes are specified using device-independent pixels (DIPs), which at set at 96 per logical inch. A font set at 10 point in foreMonkey will therefore be slightly smaller compared so the same size in a VCL application.

4. Mouse Position: In Windows world we were used to getting the mouse position using GetCursorPos(). For crossplatform, we have to use a different approach. Lukily there is a platform object from which we can obtain the mouse coordinates (from Ralph Wesseling):

uses FMX.Platform;

p : TPointF

p := Platform.GetMousePos;

5. Unit Scope Helper: Drs Bob’s has release a simple browser tool to help you convert VCL unit names to their equivalent FMX names. http://www.bobswart.nl/blog/

6. Multiple Select: If you select multiple controls on a form, the usual selection cues are not visible. However the group of controls is selected, you can move them about as if there were a group.

7. OnKeyDown/KeyUp in Forms: Unlike a VCL form which has over 40 events that one can tap into, a FM form has only 9 events exposed. In particular it has no OneKeyDown or OnKeyUp exposed. In addition, FM forms have no KeyPreview. As recently mentioned by Chris Rolliston, “Looking at the source, I’ve found the situation is in effect an enforced KeyPreview=True – the only window from an OS POV is the form itself, which
then passes on key events to the controls. While there are no OnKeyDown and OnKeyUp events exposed by TForm, you can just override the form’s KeyDown and KeyUp methods:”

type
  TForm1 = class(TForm)
    Memo1: TMemo;
  private
  public
    procedure KeyDown(var Key: Word; var KeyChar: Char; Shift:
TShiftState); override;
  end;

//...

procedure TForm1.KeyDown(var Key: Word; var KeyChar: Char; Shift:
TShiftState);
begin
  if Key = vkEscape then
    Close
  else
    inherited;
end;

Rolliston goes on to suggest that adding KeyPreview to FM forms should be straightforward and supplies the necessary code to accomplish this.

From https://forums.embarcadero.com/thread.jspa?threadID=60054&tstart=0.

8. Where are my Anchors gone? Possibly one of the biggest surprises for many was the absence of the anchor property in FM controls. This has been discussed before and refer the reader to Update 2 on this page.

9. Glyphs on buttons Question (Gaetan Maerten): I have made a simple app with an OK and Cancel button, and now I am trying to find how I can add the standard OK and Cancel glyphs?

Answer (Chris Rolliston): With the TButton object selected, add a TImage (*not* a TImageControl) to it, assign the image’s Bitmap property, and set the image’s HitTest property to False so that any mouse events float through to the button. You also might want to use a TLabel control for the button’s text instead of using the button’s own Text property, so as to make sure it all aligns nicely.

10. Writing text on a TImage (GIAN 55)

Code to write text on a TImage canvas:


procedure TForm2.Button1Click(Sender: TObject);
var
LRect: TRectF;
begin
myimage.Bitmap.LoadFromFile(CurrDir+'\bg.bmp');  // delphi need a brackground to write on

LRect.Create(0, 0, 300, 300);
myimage.Bitmap.Canvas.Font.Family:='Times New Roman';
myimage.Bitmap.Canvas.Font.Size:=18;
myimage.Bitmap.Canvas.Fill.Color:=claBlack;
myimage.Bitmap.Canvas.FillText(LRect, 'Delphi XE2 for iOS', True, 255, [],TTextAlign.taLeading,TTextAlign.taCenter);
myimage.Bitmap.BitmapChanged;
end;

11. More on Fuzzy Font. Not happy with the fuzzy fonts rendered by fireMonkey? Want to use cleartype? If so consider using a replacement canvas for fireMonkey by Mattias Anderson. Here is the contents of the readme file:

FMX.Canvas.VPR
==============

Description:

FMX.Canvas.VPR is a new FireMonkey TCanvas implementation that uses the
open source polygon rasterizer VPR for all of its rendering tasks.

How to use:

Add FMX.Canvas.VPR as the first unit in the project file of your
FireMonkey project.

Advantages:

- perfect antialiasing (superior to GDI+ and D2D);
- high performance;
- minimal API dependencies;
- support for gamma correction;
- support for cleartype font rendering;
- can be easily ported to other platforms.

Copyright (C) 2011 by Mattias Andersson

12. FastMM for Delphi XE2. For user of FastMM, Pierre Le Riche has released a version for Delphi XE2. FastMM is a memory manager and debugger tool. For more information consult this blog and this stackoverflow question.

13. Using Lua with Delphi XE2Lua is a high performance, light-weight and easy to use scripting language that games writers often use as a lightweight embedded language to develop the game’s AI for example. Lua4Delphi allows someone to use Lua from within a Delphi application. Delphi3Lua provides full Lua integration.

14. Creating Components at Runtime. Here is a simple example from Peter Soderman for creating a string grid at runtime:

procedure TForm1.Button1Click(Sender: TObject);
var
  p: TPanel;
  sg: TStringGrid;
begin
  p := TPanel.Create(Self);
  sg := TStringGrid.Create(Self);
  sg.Parent := p;
  p.Parent := Self;
  sg.Align := TAlignLayout.alClient;
  p.Align := TAlignLayout.alLeft;
end;

15. Adding a column to StringGrid. Peter Soderman reports how to add a column to a stringgrid at runtime as well as setting a cell’s text:

StringGrid1.AddObject(TStringColumn.Create(Self));

To set the text in a given cell:

StringGrid1.Cells[aCol,aRow] := ‘Hello!’;

16. How do I set the colour of the text of a TLabel Set the color of the font in the style editor but other on attributes in the property editor.