* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
BGRABitmap and LazPaint / Re: Material Design
« Last post by Handoko on Today at 07:49:02 am »
@lainz

Can you add tab stop support?
2
Other / Re: TEdit with rounded corners.
« Last post by edgarrod71 on Today at 07:43:38 am »
hi, Thank you, it's strange, because I put Tedits on a panel and they worked, nevertheless I accept your code, now it looks more clean and failproof. :)
3
Third party / Re: Online Package Manager
« Last post by GetMem on Today at 06:59:09 am »
Hi matthius,

I saw the packages you sent, but unfortunately I cannot compile them. The new version of the "Extended Packages",  "SuperForm",  "Ancestro Packages" are not working.  All the other packages are depending on the "Extended Packages", so those are not working too.  The only one I managed to compile is "Alcinoe". More over the author, description, license info is missing from the lpk files.
"Virtualdbtreeex", "Fortes Report debugged" are already in the central repository. I cannot add the same package twice, each meta/lazarus package name must be unique. If you wish to work with different version of the same package, you should create a private repository(see attached image) + install a local http server on your computer.


regards,
GetMem
4
Beginners / Re: Find text
« Last post by Jurassic Pork on Today at 05:30:10 am »
hello,
The best solution is probably learning to master regular expressions.
maybe with the help of the ReplaceRegExpr function from the Regexpr unit :
example to replace all the myint strings by yourint in this text :
Quote
extern int myint;
int           myint;
int      myint=1;
int        myint       = 30;
    int    myint;
int myint, myotherint=8;
for(int i=myint; ...
double dbl;int myint;
code :
Code: Pascal  [Select]
  1. procedure TForm1.Bt_RegexprClick(Sender: TObject);
  2. var
  3.   NewStr : String;
  4.   pattern : String;
  5. begin
  6.   MemConsole.Lines.LoadFromFile(TextFileName);
  7.   pattern := '(=|,|int|double|string|bool)\s*(myint)';
  8.   NewStr := ReplaceRegExpr(pattern,MemConsole.Lines.Text,'$1 yourint',true);
  9.   MemConsole.Lines.Append(' ==== After ====');
  10.   MemConsole.Lines.Append(NewStr);
  11. end;

pattern  search first a keyword = or , or int ...   followed by 0 space or more  followed by myint.
$1 yourint in the ReplaceRegExpr : $1 leaves the first part of the pattern like the original string

Result in Attachment.

Not perfect :    i=myint;  becomes i= yourint;

Friendly, J.P
5
General / Re: how can i show two digit in spinedit?
« Last post by majid.ebru on Today at 04:58:27 am »
Thank you
6
Third party / Re: Online Package Manager
« Last post by matthius on Today at 04:55:20 am »
Hello !

First, i had added Extended Packages to packages.lazarus-ide.org.
But i had wanted to add the rest of every packages i use from another computer, included Extended.
But i cannot send any package now and my packages are not added.

Packages tried to add :
virtualdbtreeex
Fortes Report debugged
ExtPascal adapted
SuperForm
Ancestro Packages
ExtHML
CompoPerso
...
7
LCL / Re: is it possible to stream TObjectList?
« Last post by kapibara on Today at 04:27:16 am »
You want to write a component to stream. Someone hopefully pops in and shows exactly how to do that. I have done something similar, saving object data to streams, field by field. This is more work of course. Anyway, lets say you want to save an instance of TMyObject this way. Add a SaveToStream procedure to TMyObject and iterate through the list of objects, calling SaveToStream for each object in the list. In the example below there is only one field in the class. If there are more fields, they have to be saved in the same manner.

Code: Pascal  [Select]
  1. type
  2.   TMyObject = class
  3.   public
  4.     Name: string;
  5.     procedure SaveToStream(AStream: TStream);
  6.     procedure LoadFromStream(AStream: TStream);
  7.   end;
  8.  
  9. procedure TMyObject.SaveToStream(AStream: TStream);
  10. var
  11.   Len: Integer;
  12. begin
  13.   Len := Length(Name);
  14.   AStream.Write(Len, SizeOf(Len));
  15.   AStream.Write(PChar(Name)^, Len);
  16. end;
  17.  
  18. procedure TMyObject.LoadFromStream(AStream: TStream);
  19. var
  20.   Len: Integer;
  21. begin
  22.   AStream.Read(Len, SizeOf(Len));
  23.   SetString(Name, PChar(nil), Len);
  24.   AStream.Read(PChar(Name)^, Len);
  25. end;
8
Databases / tibconnection parameters
« Last post by 3rdshiftcoder on Today at 03:38:48 am »
Hi-

I  spent tonight teaching myself a little about charsets. I wonder with tibconnection how to protect controls so only utf8 characters can get accepted. I read where someone chose these for zeos zconnection but don't know if they are the same:

http://forum.lazarus-ide.org/index.php?topic=33741.0

codepage=UTF8
controls_cp=CP_UTF8

Also, do I have to set anything with the font for charset?

I can put charset in object inspector property for tibconnection as: UTF8.

I also looked at encoding by right clicking in editor and looking at file settings and encoding.

Thx. for any tricks and letting me know correct settings for tibconnection param or where I can find that info.

I am interested if the right settings will block the controls from getting invalid data. For instance 1252 is only supposed to match utf8 for ascii characters so like what if someone wanted to type 1252 data that didn't match utf8 from the clipboard!

 I noticed if I put the params in tibconnection in wrong from above the code still ran without any warnings.

Have cool week,
3rdshiftcoder
9
LCL / Re: A simpler undo / redo class for TMemo
« Last post by tomitomy on Today at 03:32:16 am »
Fix the OnChange bug (https://bugs.freepascal.org/view.php?id=32669).

uhistory.pas:
Code: Pascal  [Select]
  1. unit uhistory;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, StdCtrls, lazUTF8, Clipbrd;
  9.  
  10. type
  11.  
  12.   PStep = ^TStep;
  13.  
  14.   // 单步历史记录数据
  15.   // one step of history data
  16.   TStep = record
  17.     BytePos  : SizeInt;
  18.     SelStart : SizeInt; // used to restore the cursor position(用于恢复光标位置)
  19.     InsStr   : string;
  20.     DelStr   : string;
  21.   end;
  22.  
  23.   { THistory }
  24.  
  25.   THistory = class
  26.   private
  27.     FMemo        : TMemo;
  28.     FSteps       : TList;         // history records data(历史记录数据)
  29.     FIndex       : Integer;       // history index, based 0(历史记录索引,从 0 开始)
  30.     FOldOnChange : TNotifyEvent;
  31.     FInEdit      : Boolean;
  32.  
  33.     // OnChange 事件之前的 FMemo 内容
  34.     // the content of FMemo before OnChange event
  35.     FPrevContent : string;
  36.     FSize        : SizeInt;       // all steps size(所有历史步骤的总大小)
  37.  
  38.     FixOnChangeBug : Boolean;
  39.  
  40.     function    GetStep(AIndex: Integer): PStep; inline;
  41.     function    CurStep: PStep; inline;
  42.  
  43.     procedure   AddStep(ABytePos, ASelStart: SizeInt; AInsStr, ADelStr: string);
  44.     procedure   DelStep(AIndex: Integer);
  45.  
  46.     procedure   MemoOnChange(Sender: TObject);
  47.  
  48.     function    StrDiff(const ACurContent: string;
  49.                         out ABytePos, ASelStart: SizeInt;
  50.                         out AInsStr, ADelStr: string): Boolean;
  51.   public
  52.     constructor Create(AMemo: TMemo);
  53.     destructor  Destroy; override;
  54.  
  55.     function    CanUndo: Boolean; inline;
  56.     function    CanRedo: Boolean; inline;
  57.     procedure   Undo;
  58.     procedure   Redo;
  59.  
  60.     // 你应该使用 Paste 函数粘贴文本,而不是 FMemo.PasteFromClipboard 函数,
  61.     // 否则你的粘贴操作可能需要撤销两次才能恢复到粘贴之前的状态。
  62.     // you should use Paste function to paste text instead of FMemo.PasteFromClipboard function,
  63.     // otherwise your paste operation may need to perform twice Undo to restore to the state before paste.
  64.     procedure   PasteText;
  65.  
  66.     // 你应该使用 DeleteText 函数删除文本,而不是 FMemo.Text := '' 方法,
  67.     // 否则你的删除操作可能不会触发 OnChange 事件。
  68.     // you should use the DeleteText function to delete text instead of the FMemo.Text := '' method,
  69.     // otherwise your delete operation may not trigger the OnChange event.
  70.     procedure   DeleteText;
  71.                            
  72.     procedure   Reset; inline;
  73.     property    Size: SizeInt read FSize;
  74.   end;
  75.  
  76. implementation
  77.  
  78. { THistory }
  79.  
  80. function THistory.GetStep(AIndex: Integer): PStep; inline;
  81. begin
  82.   Result := PStep(FSteps[AIndex]);
  83. end;
  84.  
  85. function THistory.CurStep: PStep; inline;
  86. begin
  87.   Result := GetStep(FIndex);
  88. end;
  89.  
  90. procedure THistory.AddStep(ABytePos, ASelStart: SizeInt; AInsStr, ADelStr: string);
  91. begin
  92.   DelStep(FIndex + 1);
  93.  
  94.   FSteps.Add(new(PStep));
  95.   Inc(FIndex);
  96.   Inc(FSize, Sizeof(TStep) + Length(AInsStr) + Length(ADelStr));
  97.   with CurStep^ do begin
  98.     BytePos  := ABytePos;
  99.     SelStart := ASelStart;
  100.     InsStr   := AInsStr;
  101.     DelStr   := ADelStr;
  102.   end;
  103. end;
  104.  
  105. procedure THistory.DelStep(AIndex: Integer);
  106. var
  107.   i: Integer;
  108.   Step: PStep;
  109. begin
  110.   for i := FSteps.Count - 1 downto AIndex do begin
  111.     Step := GetStep(i);
  112.     Dec(FSize, Sizeof(TStep) + Length(Step^.InsStr) + Length(Step^.DelStr));
  113.     Step^.InsStr := '';
  114.     Step^.DelStr := '';
  115.     dispose(Step);
  116.     FSteps.Delete(i);
  117.   end;
  118.   FIndex := AIndex - 1;
  119. end;
  120.  
  121. constructor THistory.Create(AMemo: TMemo);
  122. begin
  123.   inherited Create;
  124.   FSteps := TList.Create;
  125.  
  126.   FMemo := AMemo;
  127.   FOldOnChange := FMemo.OnChange;
  128.   FMemo.OnChange := @MemoOnChange;
  129.  
  130.   FPrevContent := FMemo.Text;
  131.   FIndex := -1;
  132.  
  133.   FInEdit := True;
  134. end;
  135.  
  136. destructor THistory.Destroy;
  137. begin
  138.   FMemo.OnChange := FOldOnChange;
  139.   FMemo := nil;
  140.  
  141.   DelStep(0);
  142.   FSteps.Free;
  143.   inherited Destroy;
  144. end;
  145.  
  146. procedure THistory.MemoOnChange(Sender: TObject);
  147. var
  148.   CurContent, InsStr, DelStr: string;
  149.   BytePos, SelStart: SizeInt;
  150. begin
  151.   if FInEdit then begin
  152.     CurContent := FMemo.Text;
  153.     if StrDiff(CurContent, BytePos, SelStart, InsStr, DelStr) then
  154.       AddStep(BytePos, SelStart, InsStr, DelStr);
  155.     FPrevContent := CurContent;
  156.   end;
  157.  
  158.   FixOnChangeBug := False;
  159.  
  160.   if Assigned(FOldOnChange) then
  161.     FOldOnChange(Sender);
  162. end;
  163.  
  164. function THistory.StrDiff(const ACurContent: string;
  165.   out ABytePos, ASelStart: SizeInt;
  166.   out AInsStr, ADelStr: string): Boolean;
  167. var
  168.   CurStart, CurPos, CurEnd, PrevPos: PChar;
  169.   CurLen, PrevLen, DiffLen: SizeInt;
  170.   CharLen: Integer;
  171. begin
  172.   CurStart := PChar(ACurContent);
  173.   CurPos := CurStart;
  174.   PrevPos := PChar(FPrevContent);
  175.  
  176.   CurLen := Length(ACurContent);   // Use Length(string) DO NOT use Length(PChar)
  177.   PrevLen := Length(FPrevContent);
  178.   DiffLen := CurLen - PrevLen;
  179.  
  180.   if DiffLen < 0 then
  181.     CurEnd := CurPos + CurLen - 1
  182.   else if DiffLen > 0 then
  183.     CurEnd := CurPos + PrevLen - 1
  184.   else begin
  185.     Result := False;
  186.     Exit;
  187.   end;
  188.  
  189.   while (CurPos <= CurEnd) do begin
  190.     if CurPos^ <> PrevPos^ then Break;
  191.     Inc(CurPos);
  192.     Inc(PrevPos);
  193.   end;
  194.  
  195.   Utf8TryFindCodepointStart(CurStart, CurPos, CharLen);
  196.   ABytePos := CurPos - CurStart + 1;
  197.  
  198.   if DiffLen > 0 then begin
  199.     AInsStr := Copy(ACurContent, ABytePos, DiffLen);
  200.     ADelStr := '';
  201.   end else begin
  202.     AInsStr := '';
  203.     ADelStr := Copy(FPrevContent, ABytePos, -DiffLen);
  204.   end;
  205.   ASelStart := FMemo.SelStart;
  206.  
  207.   Result := True;
  208. end;
  209.  
  210. function THistory.CanUndo: Boolean; inline;
  211. begin
  212.   Result := FIndex >= 0;
  213. end;
  214.  
  215. function THistory.CanRedo: Boolean; inline;
  216. begin
  217.   Result := FIndex < FSteps.Count - 1;
  218. end;
  219.  
  220. procedure THistory.Undo;
  221. var
  222.   NewSelStart: SizeInt;
  223. begin
  224.   if FIndex < 0 then Exit;
  225.   FInEdit := False;
  226.  
  227.   FixOnChangeBug := True;
  228.  
  229.   // FPrevContent == FMemo.Text
  230.   with CurStep^ do begin
  231.     if InsStr <> '' then begin
  232.       Delete(FPrevContent, BytePos, Length(InsStr));
  233.       NewSelStart := SelStart - UTF8LengthFast(InsStr);
  234.     end;
  235.     if DelStr <>'' then begin
  236.       Insert(DelStr, FPrevContent, BytePos);
  237.       NewSelStart := SelStart + UTF8LengthFast(DelStr);
  238.     end;
  239.   end;
  240.   FMemo.Lines.Text := FPrevContent;
  241.   FMemo.SelStart := NewSelStart;
  242.   Dec(FIndex);
  243.  
  244.   if FixOnChangeBug then MemoOnChange(FMemo);
  245.  
  246.   FInEdit := True;
  247. end;
  248.  
  249. procedure THistory.Redo;
  250. var
  251.   NewSelStart: SizeInt;
  252. begin
  253.   if FIndex >= FSteps.Count - 1 then Exit;
  254.   FInEdit := False;
  255.  
  256.   FixOnChangeBug := True;
  257.  
  258.   Inc(FIndex);
  259.   // FPrevContent == FMemo.Text
  260.   with CurStep^ do begin
  261.     if DelStr <> '' then begin
  262.       Delete(FPrevContent, BytePos, Length(DelStr));
  263.       NewSelStart := SelStart;
  264.     end;
  265.     if InsStr <> '' then begin
  266.       Insert(InsStr, FPrevContent, BytePos);
  267.       NewSelStart := SelStart;
  268.     end;
  269.   end;
  270.   FMemo.Lines.Text := FPrevContent;
  271.   FMemo.SelStart := NewSelStart;
  272.  
  273.   if FixOnChangeBug then MemoOnChange(FMemo);
  274.  
  275.   FInEdit := True;
  276. end;
  277.  
  278. function UTF8PosToBytePos(const AStr: string; const ASize: SizeInt; APos: SizeInt): SizeInt;
  279. begin
  280.   if APos < 1 then Result := -1 else Result := 0;
  281.  
  282.   while (APos > 1) and (Result < ASize) do begin
  283.     case AStr[Result] of
  284.       // #0..#127: Inc(Result);
  285.       #192..#223: Inc(Result, 2);
  286.       #224..#239: Inc(Result, 3);
  287.       #240..#247: Inc(Result, 4);
  288.       else Inc(Result);
  289.     end;
  290.     Dec(APos);
  291.   end;
  292.  
  293.   Inc(Result)
  294. end;
  295.  
  296. procedure THistory.PasteText;
  297. var
  298.   BytePos: SizeInt;
  299.   ClipBoardText: string;
  300. begin
  301.   FInEdit := False;
  302.  
  303.   ClipBoardText := ClipBoard.AsText;
  304.   if ClipBoardText <> '' then begin
  305.     FixOnChangeBug := True;
  306.  
  307.     // FPrevContent == FMemo.Text
  308.     BytePos := UTF8PosToBytePos(FPrevContent, Length(FPrevContent), FMemo.SelStart + 1);
  309.     AddStep(BytePos, FMemo.SelStart, ClipBoardText, FMemo.SelText);
  310.     FMemo.SelText := ClipBoardText;
  311.     FPrevContent := FMemo.Text;
  312.  
  313.     if FixOnChangeBug then MemoOnChange(FMemo);
  314.   end;
  315.  
  316.   FInEdit := True;
  317. end;
  318.  
  319. procedure THistory.DeleteText;
  320. var
  321.   BytePos: SizeInt;
  322. begin
  323.   FInEdit := False;
  324.  
  325.   if FMemo.SelLength > 0 then begin
  326.     FixOnChangeBug := True;
  327.  
  328.     // FPrevContent == FMemo.Text
  329.     BytePos := UTF8PosToBytePos(FPrevContent, Length(FPrevContent), FMemo.SelStart + 1);
  330.     AddStep(BytePos, FMemo.SelStart, '', FMemo.SelText);
  331.     FMemo.SelText := '';
  332.     FPrevContent := FMemo.Text;
  333.  
  334.     if FixOnChangeBug then MemoOnChange(FMemo);
  335.   end;
  336.  
  337.   FInEdit := True;
  338. end;
  339.  
  340. procedure THistory.Reset; inline;
  341. begin
  342.   DelStep(0);
  343.   FPrevContent := FMemo.Text;
  344. end;
  345.  
  346. end.
10
Linux / Re: Linux TUN
« Last post by benohb on Today at 01:53:12 am »
what do you want to do . Maybe there is another way
shared some of your thoughts :D
Pages: [1] 2 3 ... 10

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus