📄 tntdbctrls.pas
字号:
Redraw := (Style <> csSimple) and HandleAllocated;
if Redraw then Items.BeginUpdate;
try
if NewValue = '' then I := -1 else I := Items.IndexOf(NewValue);
ItemIndex := I;
finally
Items.EndUpdate;
end;
if I >= 0 then Exit;
end;
if Style in [csDropDown, csSimple] then Text := NewValue;
end;
end;
function TTntDBComboBox.GetComboValue: Variant;
var
I: Integer;
begin
if Style in [csDropDown, csSimple] then Result := Text else
begin
I := ItemIndex;
if I < 0 then Result := '' else Result := Items[I];
end;
end;
{ TTntDBCheckBox }
procedure TTntDBCheckBox.CreateWindowHandle(const Params: TCreateParams);
begin
CreateUnicodeHandle(Self, Params, 'BUTTON');
end;
procedure TTntDBCheckBox.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
function TTntDBCheckBox.IsCaptionStored: Boolean;
begin
Result := TntControl_IsCaptionStored(Self);
end;
function TTntDBCheckBox.GetCaption: TWideCaption;
begin
Result := TntControl_GetText(Self)
end;
procedure TTntDBCheckBox.SetCaption(const Value: TWideCaption);
begin
TntControl_SetText(Self, Value);
end;
function TTntDBCheckBox.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self);
end;
function TTntDBCheckBox.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntDBCheckBox.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntDBCheckBox.Toggle;
var
FDataLink: TDataLink;
begin
inherited;
FDataLink := TDataLink(Perform(CM_GETDATALINK, 0, 0)) as TFieldDataLink;
FDataLink.UpdateRecord;
end;
procedure TTntDBCheckBox.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
function TTntDBCheckBox.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
{ TTntDBRichEdit }
constructor TTntDBRichEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
inherited ReadOnly := True;
FAutoDisplay := True;
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnEditingChange := EditingChange;
FDataLink.OnUpdateData := UpdateData;
end;
destructor TTntDBRichEdit.Destroy;
begin
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
procedure TTntDBRichEdit.Loaded;
begin
inherited Loaded;
if (csDesigning in ComponentState) then
DataChange(Self)
end;
procedure TTntDBRichEdit.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (FDataLink <> nil) and
(AComponent = DataSource) then DataSource := nil;
end;
function TTntDBRichEdit.UseRightToLeftAlignment: Boolean;
begin
Result := DBUseRightToLeftAlignment(Self, Field);
end;
procedure TTntDBRichEdit.BeginEditing;
begin
if not FDataLink.Editing then
try
if FieldIsBlobLike(Field) then
FDataSave := Field.AsString{TNT-ALLOW AsString};
FDataLink.Edit;
finally
FDataSave := '';
end;
end;
procedure TTntDBRichEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
if FMemoLoaded then
begin
if (Key = VK_DELETE) or (Key = VK_BACK) or
((Key = VK_INSERT) and (ssShift in Shift)) or
(((Key = Ord('V')) or (Key = Ord('X'))) and (ssCtrl in Shift)) then
BeginEditing;
end;
end;
procedure TTntDBRichEdit.KeyPress(var Key: AnsiChar);
begin
inherited KeyPress(Key);
if FMemoLoaded then
begin
if (Key in [#32..#255]) and (Field <> nil) and
not Field.IsValidChar(Key) then
begin
MessageBeep(0);
Key := #0;
end;
case Key of
^H, ^I, ^J, ^M, ^V, ^X, #32..#255:
BeginEditing;
#27:
FDataLink.Reset;
end;
end else
begin
if Key = #13 then LoadMemo;
Key := #0;
end;
end;
procedure TTntDBRichEdit.Change;
begin
if FMemoLoaded then
FDataLink.Modified;
FMemoLoaded := True;
inherited Change;
end;
procedure TTntDBRichEdit.CNNotify(var Message: TWMNotify);
begin
inherited;
if Message.NMHdr^.code = EN_PROTECTED then
Message.Result := 0 { allow the operation (otherwise the control might appear stuck) }
end;
function TTntDBRichEdit.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TTntDBRichEdit.SetDataSource(Value: TDataSource);
begin
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
end;
function TTntDBRichEdit.GetDataField: WideString;
begin
Result := FDataLink.FieldName;
end;
procedure TTntDBRichEdit.SetDataField(const Value: WideString);
begin
FDataLink.FieldName := Value;
end;
function TTntDBRichEdit.GetReadOnly: Boolean;
begin
Result := FDataLink.ReadOnly;
end;
procedure TTntDBRichEdit.SetReadOnly(Value: Boolean);
begin
FDataLink.ReadOnly := Value;
end;
function TTntDBRichEdit.GetField: TField;
begin
Result := FDataLink.Field;
end;
procedure TTntDBRichEdit.InternalLoadMemo;
var
Stream: TStringStream{TNT-ALLOW TStringStream};
begin
if PlainText then
Text := GetAsWideString(Field)
else begin
Stream := TStringStream{TNT-ALLOW TStringStream}.Create(Field.AsString{TNT-ALLOW AsString});
try
Lines.LoadFromStream(Stream);
finally
Stream.Free;
end;
end;
end;
procedure TTntDBRichEdit.LoadMemo;
begin
if not FMemoLoaded and Assigned(Field) and FieldIsBlobLike(Field) then
begin
try
InternalLoadMemo;
FMemoLoaded := True;
except
{ Rich Edit Load failure }
on E:EOutOfResources do
Lines.Text := WideFormat('(%s)', [E.Message]);
end;
EditingChange(Self);
end;
end;
procedure TTntDBRichEdit.DataChange(Sender: TObject);
begin
if Field <> nil then
if FieldIsBlobLike(Field) then
begin
if FAutoDisplay or (FDataLink.Editing and FMemoLoaded) then
begin
{ Check if the data has changed since we read it the first time }
if (FDataSave <> '') and (FDataSave = Field.AsString{TNT-ALLOW AsString}) then Exit;
FMemoLoaded := False;
LoadMemo;
end else
begin
Text := WideFormat('(%s)', [Field.DisplayName]);
FMemoLoaded := False;
end;
end else
begin
if FFocused and FDataLink.CanModify then
Text := GetWideText(Field)
else
Text := GetWideDisplayText(Field);
FMemoLoaded := True;
end
else
begin
if csDesigning in ComponentState then Text := Name else Text := '';
FMemoLoaded := False;
end;
if HandleAllocated then
RedrawWindow(Handle, nil, 0, RDW_INVALIDATE or RDW_ERASE or RDW_FRAME);
end;
procedure TTntDBRichEdit.EditingChange(Sender: TObject);
begin
inherited ReadOnly := not (FDataLink.Editing and FMemoLoaded);
end;
procedure TTntDBRichEdit.InternalSaveMemo;
var
Stream: TStringStream{TNT-ALLOW TStringStream};
begin
if PlainText then
SetAsWideString(Field, Text)
else begin
Stream := TStringStream{TNT-ALLOW TStringStream}.Create('');
try
Lines.SaveToStream(Stream);
Field.AsString{TNT-ALLOW AsString} := Stream.DataString;
finally
Stream.Free;
end;
end;
end;
procedure TTntDBRichEdit.UpdateData(Sender: TObject);
begin
if FieldIsBlobLike(Field) then
InternalSaveMemo
else
SetAsWideString(Field, Text);
end;
procedure TTntDBRichEdit.SetFocused(Value: Boolean);
begin
if FFocused <> Value then
begin
FFocused := Value;
if not Assigned(Field) or not FieldIsBlobLike(Field) then
FDataLink.Reset;
end;
end;
procedure TTntDBRichEdit.CMEnter(var Message: TCMEnter);
begin
SetFocused(True);
inherited;
end;
procedure TTntDBRichEdit.CMExit(var Message: TCMExit);
begin
try
FDataLink.UpdateRecord;
except
SetFocus;
raise;
end;
SetFocused(False);
inherited;
end;
procedure TTntDBRichEdit.SetAutoDisplay(Value: Boolean);
begin
if FAutoDisplay <> Value then
begin
FAutoDisplay := Value;
if Value then LoadMemo;
end;
end;
procedure TTntDBRichEdit.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
if not FMemoLoaded then LoadMemo else inherited;
end;
procedure TTntDBRichEdit.WMCut(var Message: TMessage);
begin
BeginEditing;
inherited;
end;
procedure TTntDBRichEdit.WMPaste(var Message: TMessage);
begin
BeginEditing;
inherited;
end;
procedure TTntDBRichEdit.CMGetDataLink(var Message: TMessage);
begin
Message.Result := Integer(FDataLink);
end;
function TTntDBRichEdit.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or (FDataLink <> nil) and
FDataLink.ExecuteAction(Action);
end;
function TTntDBRichEdit.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or (FDataLink <> nil) and
FDataLink.UpdateAction(Action);
end;
{ TTntDBMemo }
constructor TTntDBMemo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
inherited ReadOnly := True;
ControlStyle := ControlStyle + [csReplicatable];
FAutoDisplay := True;
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnEditingChange := EditingChange;
FDataLink.OnUpdateData := UpdateData;
FPaintControl := TTntPaintControl.Create(Self, 'EDIT');
end;
destructor TTntDBMemo.Destroy;
begin
FPaintControl.Free;
FDataLink.Free;
FDataLink := nil;
inherited Destroy;
end;
procedure TTntDBMemo.Loaded;
begin
inherited Loaded;
if (csDesigning in ComponentState) then DataChange(Self);
end;
procedure TTntDBMemo.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (FDataLink <> nil) and
(AComponent = DataSource) then DataSource := nil;
end;
function TTntDBMemo.UseRightToLeftAlignment: Boolean;
begin
Result := DBUseRightToLeftAlignment(Self, Field);
end;
procedure TTntDBMemo.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
if FMemoLoaded then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -