Software
Delphi and Lazarus
Trekking and Events
Blog and Forum
Čeština English
Main menu
Delphi and Lazarus
Top downloads
KGrid (23598x)
KControls Component Suite (19128x)
KHexEditor (5278x)
KIcon (2584x)
CAN Event Manager (463x)
 

KControls Component Suite

KControls is a freeware distribution, a flagship of tkweb. It contains all of my published components for Delphi and Lazarus. All controls have been written with the aim to become both cross-IDE compatible (Delphi/C++Builder VCL and Lazarus LCL) and cross-platform compatible in Lazarus. There are some exceptions to this scheme, see below.

Components included
TKGrid - powerfull control for working with table data, replacement for TStringGrid and TDrawGrid - full compatibility and lot of new features
TKDBGrid - control for working with database tables, possible replacement for TDBGrid
TKMemo - native replacement for TMemo/TRichEdit - written from scratch, great features, full RTF support etc.
TKHexEditor - another useful control for binary file editing
TKIcon - powerfull component for working with icons and cursors (files *.ico and *.cur, works only on Windows)
TKPrintPreview - control for displaying print preview, it is part of KControls built in printing capabilities, every visual control supports printing and previewing
TKPrintPreviewDialog - nonvisual component - dialog - for an easy print preview implementation
TKPrintSetupDialog - nonvisual component - dialog - for an easy implementation of printing preferences
TKCustomControl - a base for your visual controls, for which you want to implement e.g. printing and previewing capabilities in Delphi or Lazarus (just 2 short functions to write).
TKNumberEdit - edit control to input numbers in various formats
TKFileNameEdit - edit control to input file names
TKLinkLabel - label to show clickable link
TKGradientLabel - label with gradient background
TKLog - component for event logging
TKPercentProgressBar - custom drawn progress bar which shows actual percentage of the progress
TKBrowseFolderDialog - wrapper for the standard Windows API browse for folder dialog (works only on Windows)
TKBitBtn - like TBitBtn - draws PNG and alpha channel correctly in Delphi, has WordWrap property, works in Lazarus as well
TKColorButton - just another button to pick color
TKPageControl - page control written from scratch with custom painted tab panel, has tab icons and close button icon

Notes

KControls is provided free on 'as is' basis, with complete source code. However, it is licensed software. More information about license can be found in source file headers.

All controls support Delphi and Lazarus IDEs fully. But there are some exceptions: TKIcon and TKBrowseFolderDialog work only on Windows and printing and previewing might not work in some widgetsets in Lazarus.

Note: In Delphi only VCL is supported. FMX will never be supported.

Donations

If you want to donate for further development of KControls just think about building your own photovoltaics and using the WATTrouter device produced by our company. You will save lots of energy and it will be the best donation to me you can make!

Screenshots (click the images to enlarge)

 
KControls components (Windows Vista)KControls components (Windows XP/GTK2runtine)
 
KMemo rich text editor showing the KMemo manual.KMemo rich text editor showing more complex sample RTF document.

Repository - development versions

You may now download newest development version at bitbucket. Please download and try this version if something is not working in the official release listed below.

Downloading KControls

Important note: When installing the packages in Delphi XE2 and later you must add "Vcl;Vcl.Imaging" to Unit Scope Names in Delphi Options/Library! Otherwise the packages won't compile!

FileVersionNumber of
downloads
Available for:Changes
kcontrols_1.7.zip1.76355Delphi 7+,Lazarus 1.2.2+, C++Builder 2007+support for RAD Studio XE8, major work on TKMemo which is already usable, bugfixes...
kcontrols_1.6.zip1.62699Delphi 6+,Lazarus 1.2.2+, C++Builder 2007+support for RAD Studio XE6, Columns property in TKDBGrid, bugfixes...
kcontrols_1.5.zip1.5376Delphi 6+,Lazarus 1.2.2+, C++Builder 2007+new components TKMemo, TKBitBtn, TKColorButton, some bugfixes...
kcontrols_1.4.zip1.41023Delphi 6+, Lazarus 0.9.29(SVN#21827)+, C++Builder 2007+support for RAD Studio XE3-XE5, new components etc.
kcontrols_1.3.zip1.32737Delphi 6+, Lazarus 0.9.29(SVN#21827)+, C++Builder 2007+support for RAD Studio XE2
kcontrols_1.2.zip1.23106Delphi 6+, Lazarus 0.9.29(SVN#21827)+, C++Builder 2007+cumulative update (KGrid 1.7, KHexEditor 1.5, KIcon 2.2)
kcontrols_1.1.zip1.11111Delphi 6+, Lazarus 0.9.29(SVN#21827)+, C++Builder 2007+cumulative update (KGrid 1.6, KHexEditor 1.4, KIcon 2.1)
kcontrols_1.0.zip1.01721Delphi 6+,Lazarus 0.9.29(SVN#21827)+initial release (KGrid 1.5, KHexEditor 1.4, KIcon 1.9)

If you have a question you may ask below and I will probably answer it, after some time.

 

Home | Software | Delphi and Lazarus | Trekking, travelling | Sport | Blog

Search in comments: 
inserted: 2017-09-20 13:36:11   Reply...
From: Davo
Using the Bitbucket version of KMemo. Made a hyperlink but not able to get an 'event' fired when the link is clicked.

It does not appear on the list of events for KMemo, should I look for it somewhere else ? Or do I need register it ?
inserted: 2017-09-19 10:49:44   Reply...
From: 4AM
Hi I got some archaic project to fix and it is using your TKDBGrid (version 1.1) but i have problems with installing it. There is problem at compiling, error message: [C++ Error] KControls_CB6.cpp(3): E2209 Unable to open include file 'BASEPCH.H'. And I don't have any idea where to find it.

p.s.: I am not C++ programmer.
inserted: 2017-09-19 13:42:29   Reply...
From: tk
Well I don't know as well, because I haven't used C++ Builder since ca 2010. And I hope I won't be using it again. The only thing I remember is that C++ Builder packages were 'somehow' auto-generated from Delphi packages so there should not be a major problem, maybe the C++ Builder packages are wrong and need to be recreated. I guess you will have to figure it out yourself if no one here knows the answer (this is quite probable because usually only Delphi and Lazarus programmers come here to this forum).
inserted: 2017-09-14 15:28:47   Reply...
From: lafree
How can use tkprintpreview to preview xls file?
HOW can I use tkprintpreview for other controls like StringGrid?
Thinks a lot!
inserted: 2017-09-18 11:53:54   Reply...
From: tk
No way. The control must descend from TKCustomControl, such as TKGrid or TKMemo.
inserted: 2017-09-12 21:35:52   Reply...
From: MVD
I was reading the questions and answers and I put LazUTF8 in the uses
but now I get a compiler message for the KFunctions line 2565 and 2578 "identifier not found "UTF8UpperCase" and "UTF8LowerCase".
inserted: 2017-09-18 12:16:23   Reply...
From: tk
My answer is the same as for previous question.
The functions must be present in LazUTF8, update Lazarus if they are not there.
Of course I assume you also use the latest KControls trunk from bitbucket where this my support only refers to.
inserted: 2017-09-13 07:09:25   Reply...
From: см
Did you add LazUTF8 in the uses section of KFunctions, too?
inserted: 2017-09-12 21:06:03   Reply...
From: MVD
I tried to install the KControlslaz in lazarus (windows 10)but I got the compiler error on line 4032 KMemoRTF : error: identifier not found "UTF8Copy". I would appreciate if there was some solution.
Kind regards
inserted: 2017-09-18 11:52:44   Reply...
From: tk
UTF8Copy must be present in LazUTF8.
Check if LazUTF8.pas has this function. If not then you must update to newer Lazarus version (I recommend using the trunk via fpcupdeluxe).
inserted: 2017-09-12 10:49:34   Reply...
From: см
Hi TK,
kmemo.pas contains the following line:

cDefaultWordBreaks = [cNULL, cSPACE, '/', '\', ';', ':', '(', ')', '[', ']', '.', '?', '!'];

In this line the comma is missing and imho it should be there. Could you consider adding it?
inserted: 2017-09-18 11:33:05   Reply...
From: tk
I am not sure why it was missing but IMO it should be there too. I'll add it later.
inserted: 2017-09-10 18:05:35   Reply...
From: Milsa
You have UTF8- named procedures in source. Lazarus 1.8.0 or higher have full UTF8 support. These procedures not exist in new Lazarus.
inserted: 2017-09-11 09:12:32   Reply...
From: см
These procedures exist and are parts of LazUTF8 which should be added as „...uses ... LazUTF8‟ if you want to use Lazarus 1.8 RC.
You could check the tread started by tudi_x on 2017-08-03.
inserted: 2017-09-18 12:23:43   Reply...
From: tk
For latest KControls version from Bitbucket there is no need to add LazUTF8 anywhere to uses sections, it is already there. The version compiles fine in latest Lazarus (trunk). So perhaps the Lazarus 1.8 RC misses needed functions in LazUTF8 or you refer to some older versions of Kcontrols here?
inserted: 2017-09-07 08:59:56   Reply...
From: см
Hi.
Is it possible to determine the position (the X and Y coordinates) of the caret withing the TKMemo?
inserted: 2017-09-11 21:14:38   Reply...
From: tk
There is a protected field FCaretRect which you can use now by creating a TKmemo descendant and adding a getter for it. I'll make it publicly accessible later.
inserted: 2017-09-12 08:55:56   Reply...
From: см
Thanks,
I have modified kMemo, until you make FCaretRect public.
inserted: 2017-09-05 07:49:13   Reply...
From: см
Hi. Is it possible to have titles in hyperlinks?
(Title is shown when the hyperlink is pointed by the mouse in a pop-up text area).
MS Word supports it, but still I am not sure if it is a standard property of hyperlinks or it is something extended).
inserted: 2017-09-11 21:04:19   Reply...
From: tk
No, with current version of KMemo not.
inserted: 2017-09-04 23:27:43   Reply...
From: Josh
I have been using TKGrid, with windows and OSX ( carbon ) without issue.

As Apple are discontinuing 32bit this means only COCOA should now be used.

When I compile for a cocoa I get numerous errors.

I have latest SVN of LAZARUS and FPC, if I create a new Project withan empty form, and place a TKGRID ( Latest one from bitbucket) and compile for 64 cocoa widgetset, I get an error
FPIMAGEEXCEPTION failed to create handle.
in file intfgraphics.pas at line 3634: then raise exception FPIMAHEEXCEPTION.CREATE('Failed to create handles');

Any ideas of a fix?

Thanks in advance.
inserted: 2017-09-11 21:01:36   Reply...
From: tk
I am not sure Cocoa widgetset is ready for reasonable use. I remember having numerous problems when just trying it but it was a year ago or two.
inserted: 2017-09-11 23:25:00   Reply...
From: Josh
Hi TK,

The Cocoa widgetset has come a long way since then, and is actively being developed.
So far most components I have tried now have worked flawlessly, stringgrid is even working now, even though I don't use it.(latest trunk required as fixes seem to be applied nearly daily).
It would be a shame if KGRID could not be used with cocoa, as I think we have less than a year before Apple drop 32bit hence carbon; in favour of 64bit.
inserted: 2017-09-18 11:17:10   Reply...
From: tk
I am sorry but it seems TLazIntfImage is not ready for the Cocoa widgetset. If you need to use KGrid with Cocoa then push towards the Cocoa widgetset developer(s) to make the needed format work.

FYI: I just updated Laz from trunk on my El Capitan and tried various KControls components with Cocoa. The numerous problems I spoke about persist so I still deem the Cocoa widgetset absolutely unprepared for solid usage.
inserted: 2017-08-10 13:01:50   Reply...
From: см
Hi Tk,
I found some odd things in the behaviour of TKMemo.

Case 1. If the code below is executed as it is, it will be executed without a crash, but there will be a delay (in my case 2,5 s) shown in line
    ShowMessage ('Unlock done in ' + IntToStr(dotime) + ' ms');
    Results will be similar, if line ...//CommentLine1 is commented.

Case 2. If the code is executed after commenting the following two lines:
   NestedTable.Cells[0,0].Blocks.Text:=IntToStr(Random(10000)); //CommentLine1
   KMemo1.blocks.unLockUpdate; //CommentLine2
the entire code will be executed much faster (NestedTable.Rows[0].Cells[0].BlockStyle.Brush.Color:= clred; will take less that 16 ms).

Case 3. If line ...//CommentLine2 is commented and line ...//CommentLine1 is NOT commented
the application crashes.

So what bothers me:
  in Case 1:
    Since KMemo1 is not visible, there is no reason to perform any unlock activities. But such activities are obviously done, since 2,5 s are spent on them.
  in Case 2:
    Probably there is no reason to spend whole 2,5 seconds for performing
NestedTable.Rows[0].Cells[0].BlockStyle.Brush.Color:= clred;
    because in this case it is executed and shown properly for less than 16 ms. I suppose execution could be sped up?
  in Case 3:
    A crash is always a reason to worry.

Code is executed in Lazaruis1,8RC3 with KControls from 06.VII.2017.


function RandomString:String;
var
  Len: integer;
  i: integer;
  RetVal: string='';
begin
  Len:=trunc(Random*1000);
  for i:=0 to Len do
  begin
    RetVal:=RetVal+ char(trunc(Random*125)+30);
    if len mod (trunc(random*50)+1)=0 then RetVal:=RetVal+#13#10;
  end;
  Result:=RetVal;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   row, clm: integer;
   MergeSpan: TKCellSpan;
   StartTime,DoTime: Int64;
   NestingTable: TKMemoTable;
   NestedTable: TKMemoTable;
begin
  KMemo1.blocks.LockUpdate;
  KMemo1.Blocks.Clear;
  KMemo1.Blocks.AddTextBlock ('1');
  KMemo1.Blocks.AddTextBlock ('2');
  NestingTable:=KMemo1.Blocks.AddTable;
  NestingTable.ColCount:=1;
  NestingTable.RowCount:=1;
  NestingTable.CellStyle.BorderColor:=clRed;
  NestingTable.CellStyle.BorderWidth:=1;
  NestingTable.RequiredWidth:=500;
  NestingTable.FixedWidth:=True;
  NestingTable.ApplyDefaultCellStyle;

  NestedTable:=NestingTable.Cells[0,0].Blocks.AddTable;
  NestedTable.ColCount:=3;
  NestedTable.RowCount:=2*300;
  for row:=0 to NestedTable.RowCount-1 do
    for clm:=0 to NestedTable.ColCount-1 do
        begin
           NestedTable.Cells[clm,row].Blocks.AddTextBlock('Ln'+IntToStr(row)+';'+'C'+IntToStr(clm));
           NestedTable.Cells[clm,row].Blocks.AddParagraph;
           NestedTable.Cells[clm,row].Blocks.AddTextBlock(RandomString);
           NestedTable.Cells[clm,row].Blocks.AddParagraph;
           NestedTable.CellStyle.BorderColor:=clBlue;
           NestedTable.CellStyle.BorderWidth:=1;
           if ((clm=0) and (row in [4,5])) then NestedTable.Cells[clm,row].Blocks.Clear;
           if (row mod 3=0) and (row>2) then
             begin
               MergeSpan.ColSpan:=1;
               MergeSpan.RowSpan:=3;
               NestedTable.CellSpan[0,row]:=MergeSpan;
             end;
        end;

   NestedTable.ColWidths[0]:=50;
   NestedTable.ColWidths[1]:=50;
   NestedTable.ColWidths[2]:=200;

   NestedTable.ApplyDefaultCellStyle;
   KMemo1.blocks.unLockUpdate;
   ShowMessage ('Memo populated');
   KMemo1.Visible:=False;
   KMemo1.blocks.LockUpdate;
   NestedTable.Rows[0].Cells[0].BlockStyle.Brush.Color:= clred;
   NestedTable.Cells[0,0].Blocks.Text:=IntToStr(Random(10000)); //CommentLine1
   StartTime:=GetTickCount64;
   KMemo1.blocks.unLockUpdate; //CommentLine2
   DoTime:=GetTickCount64-StartTime;
   ShowMessage ('Unlock done in ' + IntToStr(dotime) + ' ms');

   StartTime:=GetTickCount64;
   KMemo1.Visible:=True;
   DoTime:=GetTickCount64-StartTime;
   ShowMessage ('Set visible done in ' + IntToStr(dotime) + ' ms');
end;
inserted: 2017-08-11 13:47:28   Reply...
From: tk
All 3 cases are normal/not a bug:
1. UnlockUpdate always forces the calculation of entire memo content to determine block positions, extents, etc., regardless of the memo visibility.
2. Changing font color has the same consequences as changing font size or font name. Entire memo content will be recalculated, although in this case it is not really necessary. Reason is VCL TFont class offers only generous OnChange event and not eg. OnNameChange, OnColorChange etc.
3. If you miss UnlockUpdate call after a LockUpdate, the memo behavior will be unpredictable, causing possibly exceptions/crashes. You must always pair them in your code, preferably using a try-finally section.

To speed it up now there are only 2 options as I said already:
1. Use smaller tables/documents.
2. Use another control for tables, eg. KGrid.
inserted: 2017-08-11 16:35:03   Reply...
From: см
Thanks for the clarification.

Currently I am doing the following trick:
  Code1:
    MyMemo.Visible:=false;
    DisplayTable.Blocks.LockUpdate;
    DisplayTable.BlockStyle.Brush.Color:=NewColour;
    MyMemo.Visible:=true;
and it works literally a thousand times faster than with the following code:
  Code2:
    DisplayTable.BlockStyle.Brush.Color:=NewColour;
or with:
  Code 3:
    DisplayTable.Blocks.LockUpdate;
    DisplayTable.BlockStyle.Brush.Color:=NewColour;
    DisplayTable.Blocks.UnLockUpdate;

Actually both Code2 and Code3 are equally slow.

Currently (with the trick from above and with your latest fix), I can rather say that I do not have speed issues when working with RTFs, but I use TKMemo mostly in view mode.
During generation conversion of PNGs to RTFs seems quite slow (>200 ms for image 400x325 pixels), other items seem fine from the viewpoint of speed.
inserted: 2017-08-13 11:39:39   Reply...
From: tk
You could also use some cleaner solution to circumvent the problem with generous Brush/Font OnChange event when just changing the color. For example:

var OnChangeOld: TNotifyEvent;

OnChangeOld := DisplayTable.BlockStyle.Brush.OnChange;
try
  DisplayTable.BlockStyle.Brush.OnChange := nil;
  DisplayTable.BlockStyle.Brush.Color := NewColor;
  KMemo1.Repaint;
finally
  DisplayTable.BlockStyle.Brush.OnChange := OnChangeOld;
end;
inserted: 2017-08-16 09:51:12   Reply...
From: см
Thanks,
I didi it this way, so far it seems just fine.
inserted: 2017-08-03 17:46:22   Reply...
From: tudi_x
hi,
are there any plans to release a new version of KControls that would be compiling with no issues on Lazarus 1.8RC3?
currently i added {$IFDEF FPC}LazUTF8,{$ENDIF} in order to compile.
also border style on KMemo does not seem to work.

thank you
inserted: 2017-08-03 17:53:02   Reply...
From: tudi_x
{$IFDEF FPC}
property BorderStyle default cBorderStyleDef;
{$ELSE}
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default cBorderStyleDef;
{$ENDIF}

how would the borderstyle be set in Lazarus/FPC?
inserted: 2017-08-06 11:34:54   Reply...
From: tk
To be honest, I don't know why things like 1.8 RCx come when the trunk already has 1.9. Haven't used these (IMO useless) intermediate versions so far. KControls should compile fine in latest stable version (currently 1.6.4) and recent trunk (1.9). If you cannot live with latest stable (1.6.4) then I strongly recommend using the trunk and update it through fpcupdeluxe in case some problems arise. The same for FPC.

BorderStyle normally works for me in some older trunk (1.7) and recent trunk (1.9). In Delphi I had to re-implement this property for TKCustomControl, for Lazarus default LCL behavior is used. If it does not work in Lazarus then there is clearly a bug in your 1.8 RC or your own code.
inserted: 2017-08-01 13:55:12   Reply...
From: см
Hi Tk,
I have come across the following problem- when updating elements in a form, containing a TKMemo, this action takes very long time.
The elements themselves are not related with the TKMemo.
I have created a thread with a sample in https://forum.lazarus.freepascal.org/index.php/topic,37704.0.html

I suppose something gets triggered in TKMemo without a reason. I hope you could check if the issue is fixable?
inserted: 2017-08-06 15:24:13   Reply...
From: tk
I've tested your sample (labellag.zip) and your table is very big. This causes delays even when building the table. KMemo is not suitable for such a big table. It takes a long time to calculate extents for all cells, characters in them etc. It is not like KGrid which is ready for even bigger tables and fast enough. Please use StringGrid or KGrid for bigger tables to avoid such delays. Some speed-up optimization could be implemented in KMemo in future, though, but do not count with massive speed up.

The delay in TForm1.Button2Click (changing the label caption) is caused by LCL which silently invokes TKMemo.Resize as a result of its internal autosizing operations, forcing the memo to recalculate its entire content like after resizing just the memo. I've modified the KControls trunk to ensure that each TKCustomControl descendant like KMemo only recalculates its content after its client area has really been modified. Hopefully this fix did not break anything else.
inserted: 2017-08-07 08:51:46   Reply...
From: см
Thanks for the fix, now the lag is gone...
but there is some problem with content of memo not showing at all.
I will try to reproduce separately and feedback.

If this could be a hint:
I have noticed (before) that
  KMemo1.Lockupdate.....some code....KMemo1.UNLockupdate
results in the contents of the memo not shown, so I use
  KMemo1.blocks.Lockupdate.....some code....KMemo1.blocks.UNLockupdate
which works fine.
Behaviour I observed now seems quite similar (memo not shown, scrollbar displayed as if there is content).


BTW, I have made a greater table, to demonstrate the lag better, but indeed I am fullly aware that bigger RTFs are a problem.
inserted: 2017-08-07 09:04:07   Reply...
From: см
The hint happened to be a hint for me. I tracked down all ..memo.(un)lockupdate and replaced them with ..memo.blocks.(un)lockupdate and behaviour seems okay.

You wrote „..The delay in TForm1.Button2Click (changing the label caption) is caused by LCL...‟. If this behaviour is not observed in Delhi, probably there is a bug in LCL?
inserted: 2017-08-07 09:33:15   Reply...
From: tk
I am not sure if this happens in Delphi as well, will test it later. But according to http://docwiki.embarcadero.com TControl.Resize should be called automatically immediately after the control's dimensions change. I am pretty sure the same meaning should be in LCL so we might consider this to be a bug.
inserted: 2017-07-28 22:57:44   Reply...
From: inferno
How to change the checkbox state (Checked property) for new created or cleared rows - TKGrid.RowCount:=X, KGridDiskClips.ClearRow(X), etc.
inserted: 2017-07-28 23:10:02   Reply...
From: inferno
I found it - in initialization of the cell :)
inserted: 2017-07-27 11:15:49   Reply...
From: Silvio
Hi,

i want to use Borderspacing-property of KGrid. If i change the property it is shown in IDE until closing the IDE. In the lfm-File it changes the Top and Left property instead of inserting Borderspacing-property. After restart of IDE Anchor-Property overwrites the Top and Left property. Also in the User-program Anchor without Borderspacing overwrites the Top and Left property.

I this a known problem? Is there any solution?

Silvio
inserted: 2017-08-01 10:07:59   Reply...
From: tk
Well, it is a Lazarus only property. Haven't used this so far. Please first check it works well for some standard LCL controls, such as TStringGrid. If not then there might be bug in LCL, from your description it sounds probable.
inserted: 2017-07-25 13:07:55   Reply...
From: Davo
Hi Folks, I'm back ....
I am trying to change the style of text in a TKMemo.
I have tried KMemo1.SelectionTextStyle.Font.Style but it changes the whole block where the end of the selection is. If selection spans blocks, the first part is unchanged.

Am I misunderstanding just how this function works or is it not implemented yet ?
I assume this operation must break up existing blocks so is quite complicated.

Functions like ClearSelection and SelText behave as I'd expect, work on exactly
what is selected.
inserted: 2017-08-01 09:56:50   Reply...
From: tk
Look in kmemofrm.pas how this property should be used.
inserted: 2017-08-05 10:41:04   Reply...
From: Davo
Thanks tk. Not clear enough for me I'm afraid. I guess I have to accept I'm not quite ready to use a package like this yet. Pity, it really seems to have everything I want (except, perhaps documentation suited to a user like me).
Thanks anyway.
inserted: 2017-08-09 10:27:47   Reply...
From: tk
Since KMemo is not a simple control and it is not completed yet including its docs, it needs lot of studying and testing if you want to do something more specific. Plus you should have enough experience with common VCL/LCL principles as well.

But in your case things should be rather simple. Just select some text in the memo and use:

Editor.SelectionTextStyle := MyTextStyle;

This will change the text style for any text blocks within current selection. It will split existing text blocks where the selection begins or ends, if necessary. Again this applies for the most recent KControls version from the bitbucket, there might be bugs in older code.
inserted: 2017-07-25 00:08:44   Reply...
From: wes
I had trouble compiling in Delphi 2010, getting error in KFunctions.GetFormatSettings on the line Result := TFormatSettings.Create.

In Delphi2010 SysUtils.TFormatSettings is a record not a class.

Changing the define from COMPILER12_UP to COMPILER15_UP solved the problem for me.
inserted: 2017-08-01 09:53:25   Reply...
From: tk
Thanks, I'll fix this in the trunk.
inserted: 2017-07-24 20:10:09   Reply...
From: inferno
One more question - how to disable completely any cell/row highlight? I need to prevent user for any selection - the behavior should be like like settings CanSelet:=false in OnSelectCell event. But even if I did it for all cells, there is still visible highlight of the last selected cell/row.
inserted: 2017-08-01 09:50:42   Reply...
From: tk
There is no default cell highlight. Maybe you work with the first tab of the demo? There it is explicitly done in PrepareCellPainter, see // mouse "hover" simulation for default grid colors.
inserted: 2017-07-24 11:13:52   Reply...
From: см
Hi,
Is there a way to set a font for a TKmemoTable?
Neither TKmemoTable, nor TKMemoTableCell have a .TextStyle property.
inserted: 2017-07-24 13:54:15   Reply...
From: tk
No, you have to traverse all text blocks in all cells and change the font for them.
inserted: 2017-07-24 14:40:30   Reply...
From: см
Ok,
I did

if stFontTable<>stFontCommon then
  if aMemoTable.Rows[Row].Cells[Column].Blocks.Count>0
     then for BlockIndex:=0 to aMemoTable.Rows[Row].Cells[Column].Blocks.Count-1 do
       if aMemoTable.Rows[Row].Cells[Column].Blocks[BlockIndex] is TKMemoTextBlock
         then TKMemoTextBlock(aMemoTable.Rows[Row].Cells[Column].Blocks[BlockIndex]).TextStyle.Font:=stFontTable;
inserted: 2017-07-21 18:59:50   Reply...
From: inferno
I'm trying to use TKGrid with checkboxes which are aligned center. This is done like in the KGrid demo by setting in the OnDrawCell event for columns with checkboxes:

KGrid1.CellPainter.CheckBoxHAlign := halCenter;

This works well until user clicks on the checkbox and then it appears on the left side of the cell instead of changing its state only in the center position. After editing checkbos comes back to its initial center position.

Please let me know how to fix this behavior. Thanks.
inserted: 2017-07-24 13:52:46   Reply...
From: tk
CellPainter.CheckBoxHAlign only controls painting of the checkbox frame. If you want to center your inplace editor (here certainly a TCheckBox you've created in OnEditorCreate), you have to use OnEditorResize event and center it there within the cell rectangle manually.
inserted: 2017-07-24 19:44:59   Reply...
From: inferno
I found this event before asking but I can't determine the size of the checkbox there. I now use something like this:

Inc(ARect.Left, Round(Abs((ARect.Width-16)/2)));

(16 is fixed checkbox width) but maybe you know some cleaner solution?


inserted: 2017-08-01 09:43:32   Reply...
From: tk
I am not sure 16 is always the width of a checkbox frame. In KGrids.pas I have cCheckBoxFrameSize = 13; but I am not sure now this is true either. Maybe here they're right https://stackoverflow.com/questions/1164868/how-to-get-size-of-check-and-gap-in-check-box
inserted: 2017-07-17 14:12:37   Reply...
From: Davo
Hi, more questions I'm afraid.

I'd like to read the content from KMemo (so I can write out a file thats not RFT). Seems to me that data is stored in (eg) KMemo1.Blocks and we read each block by looking at Kmemo1.Blocks.Items[x] which is a TKMemoBlock and has a property 'Text' and sure enough that has the text in it. But it does not have a TextStyle property to tell me what that text looks like.

I sort of expected it to be TKMemoTextBlock, that does have a TextStyle property. Or am I thinking about this the wrong way ?

How should I determine the style (font size etc) of a block of text in KMemo ?

David
inserted: 2017-07-18 11:42:19   Reply...
From: tk
Do as CM said. Traverse all blocks and cast them to TKMemoTextBlock if they can be. TKMemoHyperlink descends from TKMemoTextBlock so you need to cast hyperlinks only if you need to access their URL properties.
If you use tables or or other nested structures you will need to traverse the blocks in individual cells and describe the table in a specific way you need. The same for more complex structures such as nested tables or floating text fields etc.
inserted: 2017-07-18 11:17:19   Reply...
From: см
I am not sure that I get you right, but if I do:
There is a variaty of block types in TKMemo, so you have to cast the block to a TKMemoTextBox. This way the compiler and IDE would know, what it is.
Something like this:
  if (TKMemo.Blocks[index] is TKMemoTextBlock)
     then ... TKMemoTextBlock(TKMemo.Blocks[index]).TextStyle...

I am not sure, maybe you should extend it to
  if (TKMemo.Blocks[index] is TKMemoTextBlock) or (TKMemo.Blocks[index] is TKMemoHyperlink)
     then ... TKMemoTextBlock(TKMemo.Blocks[index]).TextStyle...

or to
   try ... TKMemoTextBlock(TKMemo.Blocks[index]).TextStyle...

     
     

inserted: 2017-07-18 14:09:08   Reply...
From: Davo
OK (he says doubtfully). I tried casting -
FS := TKmemoTextBlock(KMemo1.Blocks[i]).TextStyle.Font.Size;
And, indeed, it worked as you suggest. Wow, thanks !
But I really don't understand why !

The kmemo.pas (line 1860 of 12K !) says KMemo1.Blocks is TKMemoBlocks. I'm surprised it can be cast to TKMemoTextBlock but even so, where did the TextStyle info come from ?

I got a lot to learn .....

Thanks very much both of you.
inserted: 2017-07-17 13:46:32   Reply...
From: Ondrej
Can you help me please? I need change row background color by value of column value in this row.
I test this from demo:
procedure TForm1.KDBGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  R: TRect; State: TKGridDrawState);
begin
     KDBGrid1.Cell[ACol, ARow].ApplyDrawProperties;
     if State * [gdFixed, gdSelected] = [] then
     begin
          if KDBGrid1.DataSource.DataSet.FieldByName('ID').AsInteger mod 2 = 0 then
             KDBGrid1.CellPainter.Canvas.Brush.Color := KDBGrid1.Color
          else
              KDBGrid1.CellPainter.Canvas.Brush.Color:=RGB(240,240,255);
     end;
     KDBGrid1.CellPainter.DefaultDraw;
end;

This change complet grid color background if i change selected row.
I am sorry for my English
inserted: 2017-07-18 11:34:14   Reply...
From: tk
I am sure your KDBGrid1.DataSource.DataSet.FieldByName('ID').AsInteger is constant for each row. Try:
if ARow mod 2 = 0 then
inserted: 2017-07-14 01:50:22   Reply...
From: Davo
Hello, just tried to build the bitbucket version of KControls. Ubuntu, Lazarus 1.8RC2

However, following error message -

kgrids.pas(2942,15) Error: There is no method in an ancestor class to be overridden: "DoAutoAdjustLayout(const TLayoutAdjustmentPolicy;const Double;const Double;const Boolean);"

David
inserted: 2017-07-14 15:46:42   Reply...
From: см
Hi,
I had the same problem in Laz 1.8RC2.
I opened kgrids.pas.
Then I removed „Override‟ from line 2943 (or whatever):
  const AXProportion, AYProportion: Double; const AScale0Fonts: Boolean); override;

I have no idea if I should, since I do not use KGrids, it is not a problem for me.
inserted: 2017-07-15 11:37:50   Reply...
From: Davo
Thanks CM, yep, tried that, after all, the method does not exist in TKControls so override is wrong. But I found that only exposed another problem, the compiler complaining that the implementation number of parameters does not match the declaration. But it does (4) ??? Can only assume there is something else more subtle happening and the compiler is guessing as to what it is.

Sigh ...
inserted: 2017-07-16 19:11:11   Reply...
From: tk
See here: http://wiki.lazarus.freepascal.org/High_DPI.
I was perhaps too hasty introducting this because Lazarus devs were hasty with that development as well IMO. The method appeared in Lazarus trunk 1.7 for a short while and then disappeared again. Then it appeared again when LCL version was set to 1.8. But I don't know if these changes were synchronous and if your RC already supports this. Please comment out this method if you have trouble with compiling, or adapt the ifdef. Or update Lazarus.
inserted: 2017-07-17 11:11:31   Reply...
From: Davo
OK, I commented out the TKCustomGrid's DoAutoAdjustLayout and it built fine. Updated Lazarus to 1.8RC3, same results. Developers say that RC3 will be pretty much what 1.8 looks like.

I'm quite happy with 1.7 KControls right now so I'll leave that active.

Thanks for your help.

David
inserted: 2017-07-18 11:49:08   Reply...
From: tk
If you update to FPC/Lazarus trunks (eg. with fpcupdeluxe) then it will work fine (I mean latest KControls repository snapshot). I've never used release candidates, some time ago I've used last stable 1.6.4 but now I need both trunks because they contain important fixes. I really recommend using fpcupdeluxe, it is now already a very mature installer for FPC & Lazarus & cross compilers.
inserted: 2017-07-14 01:41:25   Reply...
From: Davo
Tried installing current KControls on Ubuntu running Lazarus 1.8RC2.
However, seems UTF8Copy() has now been dropped. It was present but deprecated in 1.6. See -

http://wiki.lazarus.freepascal.org/Lazarus_1.8.0_release_notes#Wrappers_for_string_functions_are_disabled

http://wiki.freepascal.org/Lazarus_1.6.0_release_notes#SysToUTF8_does_not_convert

I cannot even find the FPC docs for UTF8Copy() anymore, sure I could recently but maybe my search engine is a bit tired today !

David
inserted: 2017-07-14 15:48:47   Reply...
From: см
UTF8Copy is now located in LazUTF8.
Try to add LazUTF8 in the uses section of your code.
inserted: 2017-07-15 14:09:50   Reply...
From: Davo
Indeed CM, adding LazUTF8 to uses in KMemo and then KMemoRTF helps. But then we need UTF8UpperCase() in KFunctions and it does not help there. In fact, UTF8UpperCase() is defined in LazUTF8.pas so I am unsure why not.
Think I'll go to bed .....
inserted: 2017-07-16 11:03:02   Reply...
From: Davo
OK, its cool, my silly. Where tk has called UTF8UpperCase() in KFunctions, he has prepened the OLD unit name, LCLProc, so no amount of 'uses' clauses will change that.
So, in two places in KFunctions, LCLProc.UTF8UpperCase() needs to become just UTF8UpperCase(). And it all builds nicely, installs and runs !
Thanks tk, this is one serious component !

David
inserted: 2017-07-16 19:16:06   Reply...
From: tk
In the bitbucket repository this has been already fixed long ago.
inserted: 2017-07-05 15:02:09   Reply...
From: Alex
Hi,

in KMemo, how do I watch for selection/caret changes? I'm trying to update ToolButtons etc. without constant polling (the Demo takes 100% of one of my CPU cores with constant Action.OnUpdate calls). Is there something like an OnSelectionChange event?

I was Hooking into Memo.Blocks.OnUpdate, which works if I keep a reference to the old value - however, the caret disappears...

What is the correct way to do this?

Thank you very much for this great component!

Best,
Alex
inserted: 2017-07-11 11:31:06   Reply...
From: tk
Through actions as it is shown in the kmemoeditor demo. It works for me wo problems in Lazarus or Delphi XE (CPU time = 0 when idle) when eg. kmemo_manual.rtf or other docs I test with are loaded into the memo (I always test with latest version from bitbucket).

Constant Action.OnUpdate calls must have a reason. You will have to figure it out yourself.
inserted: 2017-07-05 15:42:20   Reply...
From: Alex
In reply to my own question...

It turned out to be simple to add, my OnSelectionChange-event is called in TKCustomMemo.Select(). However, I'm still wondering if it's the correct way to do this...
inserted: 2017-07-03 21:59:36   Reply...
From: Frank
4 Q's
1) How do I evaluate if there is any text in the KMemo textbox?
2) Can I use PrintPreview control and write my own data to the control and not have to use the Grid or kmemo controsl??
3) And is there a manual on the printpreview?
4) Do have more documentation on using Kmemo than the rtf manual in the package. I need to know more of the properties the KMemo supports.
inserted: 2017-07-11 11:18:46   Reply...
From: tk
1. if KMemo1.Text <> '' then ...
2. You have to write your own TKCustomControl descendant which is not trivial task. If you are a beginner, forget about that. If not, you have to figure it out yourself.
3. Only what's described in KControls.chm or the comments.
4. Only what's described in KControls.chm or the comments. This doc is not yet completed.
inserted: 2017-07-04 11:44:24   Reply...
From: см
A1: if len(KMemo1.Text)>0 then ...
A4: You can try the examples bundled with the component. IFAIR there are some examples with print preview.
inserted: 2017-07-04 17:41:14   Reply...
From: см
Ooops- Length(...)
inserted: 2017-07-04 11:55:54   Reply...
From: Frank
Thanks for replying... but 'len' is not found, so it doesn't work.
And if you look at the examples, there is no code to show how to manually create your own preview using the PreviewControl... you can only hook it up to the KMemo and it does it automatically.
inserted: 2017-07-04 01:07:48   Reply...
From: Frank
Q 5...
Also, using the Kmemo and printpreview... how do I turn off the "fit to page" in code??
inserted: 2017-07-11 11:21:15   Reply...
From: tk
KMemo1.PageSetup.Options := KMemo1.PageSetup.Options - [poFitToPage];
inserted: 2017-06-29 17:24:22   Reply...
From: см
Hi,
I am running the code below.
But it occurs that after selecting the text KMemo1.SelectedBlock returns nill.
Is it expected to be this way? And is it possible to determine the block to which the selected text belongs (or at least some of its characters, since they may belong to separate blocks)?

procedure TForm1.SelSomeClick(Sender: TObject);
begin
  KMemo1.Blocks.Clear;
  KMemo1.Blocks.AddTextBlock('1234567890123456789012345678901234567890');
  KMemo1.Select(9,5);
  if KMemo1.SelectedBlock = nil then ShowMessage('selblock is nill');
end;
inserted: 2017-07-11 11:10:54   Reply...
From: tk
Please read the manual about SelectedBlock. There is a note about it already. It is possible to determine the block to which the selected text belongs. But you have to traverse all text blocks and inspect their SelLength properties.
inserted: 2017-07-11 11:38:54   Reply...
From: см
Thanks, I have just downloaded https://bitbucket.org/tkweb/kcontrols/get/16a4d402ad9e.zip (latest repository), but in tkweb-kcontrols-16a4d402ad9e.zip\tkweb-kcontrols-16a4d402ad9e\help\kmemo\manual\kmemo_manual.rtf the word „SelectedBlock‟ is not mentioned at all. Maybe latest manual is not uploaded? Or maybe you are talking about: „Attributes can also be read. In such case the attributes are returned, which correspond to caret position or selection end position in the innermost container.‟?
inserted: 2017-07-12 11:16:04   Reply...
From: tk
I meant KControls.chm file which is auto-generated from the comments in unit interface sections (I've used DiPasDoc for that). The file is not stored in the repository as it is binary file, it is only present in the official releases.
Maybe also info about SelectedBlock is not yet present in the chm file. So have a look into the code first, the comments above property/method declarations.
inserted: 2017-07-14 15:39:54   Reply...
From: см
Thanks, I will check the CHM file.
inserted: 2017-06-22 08:36:20   Reply...
From: см
Hi,
I am executing the code below, trying to select a string occurring in a KMemo. It usually works, but it occurs that when the text is in a table containing merged cells things go wrong.
In the example below, I expect that „L4;C1‟ is selected, but instead the selected text is „L4;C2‟ which in located in the next column.
I have made compensation for the paragraphs (since it is two chars and they are considered as one). As far as I remember you mentioned that images are considered an extra char. Probably merged cells are also considered a char?
Could there be a way to select the found string?

The only idea I currently have is to count the number of paragraphs before the occurence, then find the position of the last paragraph before occurence of the text in the raw RTF and count images and merged cells within it (I could not find the text itself in the raw RTF, because it might be formatted).
But probably there is a more reliable and straightforward way?


procedure TForm1.cmdNestedTableClick(Sender: TObject);
var
   NestingTable: TKMemoTable;
   NestedTable: TKMemoTable;
   row, clm: integer;
   MyStream:TStream;
   FoundPos, NLCount: integer;
   MergeSpan: TKCellSpan;
begin
  KMemo1.Blocks.Clear;
  KMemo1.Blocks.AddTextBlock ('');
  KMemo1.Blocks.AddTextBlock ('');
  NestingTable:=KMemo1.Blocks.AddTable;
  NestingTable.ColCount:=1;
  NestingTable.RowCount:=1;
  NestingTable.CellStyle.BorderColor:=clRed;
  NestingTable.CellStyle.BorderWidth:=1;
  NestingTable.RequiredWidth:=200;
  NestingTable.FixedWidth:=True;
  NestingTable.ApplyDefaultCellStyle;

  NestedTable:=NestingTable.Cells[0,0].Blocks.AddTable;
  NestedTable.ColCount:=3;
  NestedTable.RowCount:=7;
  for row:=0 to NestedTable.RowCount-1 do
    for clm:=0 to NestedTable.ColCount-1 do
    begin
       NestedTable.Cells[clm,row].Blocks.AddTextBlock('L'+IntToStr(row)+';'+'C'+IntToStr(clm));
       NestedTable.Cells[clm,row].Blocks.AddParagraph;
       NestedTable.CellStyle.BorderColor:=clBlue;
       NestedTable.CellStyle.BorderWidth:=1;
    end;
   NestedTable.ApplyDefaultCellStyle;

   MergeSpan.ColSpan:=1;
   MergeSpan.RowSpan:=3;
   NestedTable.CellSpan[0,3]:=MergeSpan;

    MyStream := TStringStream.Create('{\rtf1 Line1\par Line2\par Line3\par Line4\par');
    NestedTable.Cells[1, 1].Blocks.LoadFromRTFStream(MyStream);

  FoundPos:=PosEx('L4;C1',KMemo1.Text);
  if FoundPos>0 then
    begin
      NLCount:=Occurs(LeftStr(KMemo1.Text,FoundPos),#13#10); //Counts the number of the new lince characters before the occurence of the string
      dec(FoundPos,NLCount+1);
      KMemo1.Select(FoundPos,Length('L4;C1'));
    end;
end;
inserted: 2017-06-22 20:47:46   Reply...
From: tk
Cannot compile the example:
Main.pas(678,16) Error: Identifier not found "Occurs".
inserted: 2017-06-23 07:12:14   Reply...
From: см
Sorry, here it is:

//Counts the number of occurrences of a „Separator‟ withing „Str‟.
function Occurs(str, separator: string): integer;
var
  i, nSep: integer;
  SeparatorLength: Integer;
begin
  SeparatorLength := Length(separator);
  nSep := 0;
  for i := 1 to Length(str) do
  if MidStr (str,i,SeparatorLength) = separator then
      Inc(nSep);
  Result := nSep;
end;
inserted: 2017-06-23 10:12:34   Reply...
From: tk
Do not touch cells that become invisible after merging, here Cells[0,4] and Cells[0,5]:

for row:=0 to NestedTable.RowCount-1 do
    for clm:=0 to NestedTable.ColCount-1 do
    begin
       if (clm <> 0) or not (row in [4,5]) then
       begin NestedTable.Cells[clm,row].Blocks.AddTextBlock('L'+IntToStr(row)+';'+'C'+IntToStr(clm));
         NestedTable.Cells[clm,row].Blocks.AddParagraph;
         NestedTable.CellStyle.BorderColor:=clBlue;
         NestedTable.CellStyle.BorderWidth:=1;
       end;
    end;
inserted: 2017-06-23 10:31:48   Reply...
From: см
Thanks,
If I get you right, a merged cell results in 2 characters if NOT empty, otherwise it returns 0 chars.
I hope I will succeed to make this solution practibally applicable.
inserted: 2017-06-23 11:41:47   Reply...
From: см
Instead of your code I did:

if (clm = 0) or (row in [4,5]) then
  NestedTable[clm,row].blocks clear and the effect is the same.
I suppose it is FixEmptyBlocks (which I use in the full code) that adds paragraphs in my cells.

I still have an issue with 1 char offset (occurs sporadically) but I believe it is fixable.
inserted: 2017-06-23 13:34:29   Reply...
From: tk
Better do not touch them as I said. I tried blocks.clear+fixemptyblocks as well but there is some problem with them, maybe even some bug there.
inserted: 2017-06-23 14:32:25   Reply...
From: см
Okay,
Thanks once again!
I will try to find a way to leave them intact.
If it matters, my case is rather „fixemptyblocks+blocks.clear‟ than „blocks.clear+fixemptyblocks‟, but I am still not sure.
inserted: 2017-06-29 10:44:25   Reply...
From: см
Just to mention that that there is no possible way for my example to work, because I have used
  FoundPos:=PosEx('L4;C1',KMemo1.Text);
instead of
  FoundPos:=UTF8Pos('L4;C1',KMemo1.Text);
inserted: 2017-06-10 00:51:00   Reply...
From: LookinGood
Hi, just found KMemo and it is looking good, but I need to be able to move the Caret to the bottom of a logging file when new stuff is being added.

I looked through the Source and could not find anything. How do I move the Caret to the very bottom of the file so the user can see new stuff being logged?

I played a little with ScrollBy but can't seem to make it work for me. I am using Lazarus in Ubuntu, so this may well be a "feature" of one or both though.
inserted: 2017-06-11 11:23:46   Reply...
From: см
I cannot check right now, but I am pretty sure you can find what you need in kmemo1.ExecuteCommand(ecGoto... ) or in something similar starting with "ec".
inserted: 2017-06-12 06:44:29   Reply...
From: см
This should do: KMemo1.ExecuteCommand(ecEditorBottom);
inserted: 2017-06-06 10:31:41   Reply...
From: см
Hi TK,
I have added some highlighting functionality to TKMemo (still for a single area only).
There is still some problem in the cases when selection and highlight overlap.
Anyway, could I upload the modified source somewhere so you could see it and consider using it in TKMemo (after the issue with overlapping is solved)?
Or should I use some tool to create a patch?
inserted: 2017-06-15 15:19:11   Reply...
From: tk
1. Before making any patches, be sure to test the modifications as described in kcontrols_readme.txt, see INFO FOR CONTRIBUTORS. Test at least in Lazarus trunk (1.7 or newer) and Delphi XE or newer (you can use some evaluation version).
2. To generate patch, use TortoiseHg Workbench (select changeset, then right click, select Export and click Export patch).
3. Send patch to my email.
Older comments
My account
Recently modified

KControls Component Suite

by: tk

2015-11-16

KHexEditor

by: tk

2010-11-08

KGrid

by: tk

2010-11-08

KIcon

by: tk

2009-11-24

KGrid 1.3 released.

by: tk

2009-08-10

Recently inserted

ONEinspect

by: tk

2016-04-12

Grouping of comments

by: tk

2015-11-16

KMemo

by: tk

2015-08-12

My recent work on KMemo

by: tk

2015-07-28

Update for RAD Studio XE2

by: tk

2012-04-03