Forum > FPC development
Better code for Lazarus
(1/1)
edgarrod71:
I'm not the best programmer (probably), but when I see I can improve something, I do it. Since I couldn't work with last lazarus because of "^ñáéíóúÁÉÍÓÚÜüÑ" issue, I downgraded to v2.0.12 and linking my programs to 64 bits with it. I like dark interfaces and I was trying to modify IDE v2.0.12. When I selected new units or forms, the dialog is mostly "white" and sometimes a little slow when I go back and forth, so I changed the Form color and Font color and put ListBox and Splitter to inherit them, Splitter changed normally but not ListBox, so I took a look (lol) inside the DrawItem and found that there is a little recalculations on every item (slow) and improved the code to make my goal, so I put an onShow to calculate those "once" and redefined DrawItem. Here's the code.
this block goes on the class definition
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure FormShow(Sender: TObject); · · · procedure HelpButtonClick(Sender: TObject); procedure CancelButtonClick(Sender :TObject); procedure MultiselectCheckBoxClick(Sender :TObject); private img_W: byte; // IDEImages.Images_16.Width S96F: byte; // Scale96ToFont(4) aR: TRect; // Global Rect instead of Local FIdleConnected: boolean; FItemType: TIDEProjectItem; FSortAlphabetically: boolean; FImageIndex: Integer; · · ·
Implementation section
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TViewUnitDialog.ListboxDrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);begin if Index < 0 then Exit; with ListBox do begin if odSelected in state then begin Canvas.Brush.Color := Parent.Font.Color; Canvas.Font.Color := Parent.Color; Canvas.Font.Style := [fsBold] end else begin Canvas.Brush.Color := Parent.Color; Canvas.Font.Color := Parent.Font.Color; Canvas.Font.Style := []; // normal font end; Canvas.FillRect(aRect); IDEImages.Images_16.Draw(Canvas, 1, aRect.Top, FImageIndex); Canvas.TextOut(ARect.Left + img_W + S96F, ARect.Top, Items[Index]); // Less Calculations { This avoids blank from bottom of last item to ClientHeight } if (ClientHeight > aRect.Bottom) and (index = pred(count)) then begin Canvas.Brush.Color := Parent.Color; aR.Top := aRect.Bottom; // (aRect.Bottom - aRect.Top) * Count; aR.Bottom := ClientHeight; Canvas.FillRect(aR); end; end;end;
onShow
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TViewUnitDialog.FormShow(Sender: TObject);begin aR := ListBox.ClientRect; // must be initialized here img_W := IDEImages.Images_16.Width; S96F := Scale96ToFont(4);end;
Navigation
[0] Message Index