wwDBGrid遇到顯示(MEMO)的處理方式

這件事情的起因是因為前人開立的欄位格式是 nvarchar(max)

於是呢!在DBGrid裡面就變成了

1480584108022

要解決(Memo)顯示正常的內容,就得要在DBGrid的DrawDataCell動手腳了

procedure TForm1.wwDBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
var
  ACanvas : TCanvas;
begin
  if (Field.DataType <> ftWidememo)  then exit;
  ACanvas := twwDBGrid(Sender).Canvas;
  ACanvas.textrect(Rect,Rect.Left,Rect.Top,Field.AsString);
end;

加上後,就會顯示為

1480585258071

Delphi 10 Berlin 在tabitem加上數字

tabbarcustom
[pascal]
interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TabControl, FMX.Controls.Presentation, FMX.Edit,
FMX.EditBox, FMX.SpinBox, FMX.StdCtrls, FMX.Layouts, FMX.ListBox,
FMX.NumberBox;

type
TForm16 = class(TForm)
TabItem1: TTabItem;
TabItem2: TTabItem;
BadgeItem: TTabItem;
SpinBox1: TSpinBox;
ToolBar1: TToolBar;
Switch1: TSwitch;
ListBox1: TListBox;
ListBoxItem1: TListBoxItem;
ToolLabel: TLabel;
TabControl1: TTabControl;
procedure BadgeItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
procedure SpinBox1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Switch1Switch(Sender: TObject);
procedure StepperUpClick(Sender: TObject);
private
FBadge: Integer;
FShowBadge: Boolean;
procedure SetBadge(const Value: Integer);
procedure SetShowBadge(const Value: Boolean);
{ Private declarations }
public
{ Public declarations }
property Badge: Integer read FBadge write SetBadge;
property ShowBadge: Boolean read FShowBadge write SetShowBadge;
end;

var
Form16: TForm16;

implementation

{$R *.fmx}
{$R *.iPhone55in.fmx IOS}

procedure DrawBadge(Canvas: TCanvas; const ARect: TRectF; const Text: string;
const Color: TAlphaColor = TAlphaColorRec.Red);
const
Padding = 2;
HorzTextMargin = 6;
VertTextMargin = 4;
var
R: TRectF;
TextSize: TSizeF;
Brush: TBrush;
BadgeRadius: Single;
begin
Canvas.Font.Size := 12;
// Measure text width
TextSize := TSizeF.Create(Canvas.TextWidth(Text), Canvas.TextHeight(Text));
// Calculate badge rect
R := TRectF.Create(0, 0, HorzTextMargin * 2 + TextSize.Width, VertTextMargin * 2 + TextSize.Height);
if R.Width < R.Height then
R.Width := R.Height;
// Position rect
R := TRectF.Create(ARect.Right – R.Width, ARect.Top, ARect.Right, ARect.Top + R.Height);
R.Offset(-Padding, Padding);
// Draw badge
BadgeRadius := R.Height / 2;
Brush := TBrush.Create(TBrushKind.Solid, Color);
try
Canvas.FillRect(R, BadgeRadius, BadgeRadius, AllCorners, 1, Brush);
finally
Brush.Free;
end;
// Draw text
Canvas.Fill.Color := TAlphaColorRec.White;
Canvas.FillText(R, Text, False, 1, [], TTextAlign.Center, TTextAlign.Center);
end;

procedure TForm16.BadgeItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
begin
if ShowBadge then
DrawBadge(Canvas, ARect, FBadge.ToString);
end;

procedure TForm16.FormCreate(Sender: TObject);
begin
FBadge := 1;
end;

procedure TForm16.SetBadge(const Value: Integer);
begin
if FBadge Value then
begin
FBadge := Value;
BadgeItem.Repaint;
end;
end;

procedure TForm16.SetShowBadge(const Value: Boolean);
begin
if FShowBadge Value then
begin
FShowBadge := Value;
BadgeItem.Repaint;
end;
end;

procedure TForm16.SpinBox1Change(Sender: TObject);
begin
Badge := Trunc(SpinBox1.Value);
end;

procedure TForm16.StepperUpClick(Sender: TObject);
begin
Badge := Trunc(SpinBox1.Value);
end;

procedure TForm16.Switch1Switch(Sender: TObject);
begin
ShowBadge := Switch1.IsChecked;
end;

end.
[/pascal]
原始資料:https://community.embarcadero.com/blogs?view=entry&id=9074

Embarcadero多平台遊戲原始碼開放

Embarcadero官方釋出了幾項以Delphi/C++ Builder開發的跨平台遊戲,可以在Android/iOS/MacOS/Windows下面執行。
主要也透過遊戲原始碼分享幾個技術:
.Game loop
.Using TRectangle
.Frames UI
.Motion Sensor
.High Scores via SQLite & LiveBindings
.Object Pooling
.Sprite Sheet Animation
.App Tethering
.Cross Platform Sound

教學的影片

Delphi QA Metrics程式碼度量工具

Delphi 從2005年的Borland Developer Studio(BDS)2006版本,就開始加入QA Audits和QA Metrics可以快速把握專案的設計和程式碼品質。

qametrics

metrics

CIW – Class Interface Width
LOC – Lines of Code
NAM – Number of Accessor Methods
NOA – Number of Attributes
NOC – Number of Classes
NOIS – Number of Import Statements
NOM – Number of Members
NOP – Number of Parameters
NOPA – Number of Public Attributes
PIS – Package Interface Size
PS – Package Size

Delphi 從網路抓取圖片顯示於TBrowser在Android/OSX/iOS/Win的最佳方式

解法很簡單,就是在WebBrowser中設定一個寬與高都100%的圖片
[pascal]
const
cHtmlString = ‘<img src=%s width=100% height=100%>’;
var
UrlOfImage: string;
begin
UrlOfImage := ‘http://www.xxxx.xxx/xxx.jpg’;
WebBrowser1.LoadFromStrings(Format(cHtmlString, [UrlOfImage]), ”);
end;
[/pascal]

Linux迎接25歲生日!Delphi也趕來祝賀囉~

Linus Torvalds was the designer of the open-source operating system Linux.
Linus Torvalds was the designer of the open-source operating system Linux.

今年是Linux的25歲生日!Delphi也推出新的版本代號「Godzilla」(哥吉拉),準備讓Delphi 也能在linux上面執行了~
LinuxGodzilla

linux1_large

linux2_large

相關連結:

Happy 25th birthday, Linux

Linux Just Turned 25 and Delphi is Coming to Celebrate