Jump to content

unidbradiogroup Value


sinanaydin

Recommended Posts

  • Administrators
unit uniDBRadioGroup;
{***@@@---------------------------------------------------------------------***}
{               uniGUI Web Application Framework for Delphi                    }
{                                                                              }
{ This source code is copyrighted material.                                    }
{ Copyright (c) FMSoft Co. Ltd. 2009-2016. All rights reserved.                }
{                                                                              }
{ See License.pdf under installation folder for details.                       }
{                                                                              }
{ Developed by: Farshad Mohajeri                                               }
{ Contact: farshad@fmsoft.net - info@fmsoft.net                                }
{ http://www.unigui.com                                                        }
{ http://www.fmsoft.net                                                        }
{------------------------------------------------------------------------------}

interface

uses
  SysUtils, Classes, Controls, StdCtrls, DB, DBCtrls, UniGUIFont, UniCheckBox,
  uniRadioGroup, UniGUIClasses, uniGUICoreInterfaces, UniGUIInterfaces;

type
  TUniDBRadioGroup = class(TUniCustomRadioGroup, IUniDBControl)
  private
    { Private declarations }
    FDataLink: TFieldDataLink;
    FValues: TStrings;
    function AllowEdit: Boolean;
    procedure ActiveChange(Sender: TObject);
    procedure DataChange(Sender: TObject);
    procedure EditingChange(Sender: TObject);
    procedure UpdateData(Sender: TObject);
    function GetValue: string;
    procedure SetValues(const Value: TStrings);
    function GetButtonValue(Index: Integer): string;
  protected
    { Protected declarations }
    procedure DoSetRemoteValue(AIndex:Integer; Value: string); override;

    procedure Notification(AComponent: TComponent; Operation: TOperation); override;

    // IUniDBControl
    function GetField: TField;
    function GetDataField: WideString;
    procedure SetDataField(Value: WideString);
    function GetDataSource: TDataSource;
    procedure SetDataSource(Value: TDataSource);
    // IUniDBControl

    property DataLink:TFieldDataLink read FDataLink;

    function VCLControlClassName: string; override;

    procedure WebCreate; override;
  public
    { Public declarations }
    property Field: TField read GetField;

    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property DataField: WideString read GetDataField write SetDataField;
    property DataSource: TDataSource read GetDataSource write SetDataSource;

    property Caption;
    property ParentFont;
    property Font;
    property Align;
    property Anchors;
    property TabStop;
    property TabOrder;
    property ParentColor;
    property Color;
    property ReadOnly;
    property ClientEvents;
    property ScreenMask;
    property Items;
    property LayoutConfig;
    property Columns;
    property AutoScroll;
    property Vertical;
    property Draggable;
    property Values: TStrings read FValues write SetValues;

    property OnEndDrag;
    property OnClick;
    property OnAjaxEvent;
    property OnChangeValue;
  end;

implementation

uses
  UniGUIConst, uniGUITypes, UniDBUtils;

function TUniDBRadioGroup.VCLControlClassName: string;
begin
  Result := 'TVCLDBRadioGroup';
end;

constructor TUniDBRadioGroup.Create(AOwner: TComponent);
begin
  FDataLink := TFieldDataLink.Create;
  FDataLink.Control := Self;
  inherited;
  FValues := TStringList.Create;
end;

destructor TUniDBRadioGroup.Destroy;
begin
  FValues.Free;
  FDataLink.Free;
  inherited;
end;

procedure TUniDBRadioGroup.WebCreate;
begin
  inherited;
  PersistentEvents := PersistentEvents+[evChanged];
  KeepState := True;
  FDataLink.OnDataChange := DataChange;
  FDataLink.OnEditingChange := EditingChange;
  FDataLink.OnUpdateData := UpdateData;
  FDataLink.OnActiveChange := ActiveChange;
end;

procedure TUniDBRadioGroup.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);

  if (Operation = opRemove) and (FDataLink <> nil) and (AComponent = DataSource) then
    DataSource := nil;
end;

function TUniDBRadioGroup.AllowEdit: Boolean;
begin
  Result := DataLinkEditable(FDataLink) and (not Self.ReadOnly);
end;

procedure TUniDBRadioGroup.ActiveChange(Sender: TObject);
begin
  if (not IsDesigning) and (not IsDestroying) then
    InternalReadOnly := not AllowEdit;
end;

procedure TUniDBRadioGroup.EditingChange(Sender: TObject);
begin
  if IsLoading or IsDestroying then Exit;

  InternalReadOnly := not AllowEdit;
end;

procedure TUniDBRadioGroup.UpdateData(Sender: TObject);
begin
//
end;

procedure TUniDBRadioGroup.DataChange(Sender: TObject);
var
  FVal : string;
  FIndex, I : Integer;
begin
  if SelfUpdating then Exit;
  if IsDestroying then Exit;

  if not Assigned(FDataLink.DataSet) then Exit;

  if FDataLink.DataSet.ControlsDisabled then Exit;

  if FDataLink.Field <> nil then
  begin
    FVal := FDataLink.Field.AsString;
    FIndex := -1;
    for I := 0 to Items.Count - 1 do
      if FVal = GetButtonValue(I) then
      begin
        FIndex := I;
        Break;
      end;

    ItemIndex := FIndex;
  end;

  StateValue := GetDatasetState(FDataLink.DataSet);
end;

function TUniDBRadioGroup.GetButtonValue(Index: Integer): string;
begin
  if (Index < FValues.Count) and (FValues[Index] <> '') then
    Result := FValues[Index]
  else if Index < Items.Count then
    Result := Items[Index]
  else
    Result := '';
end;

function TUniDBRadioGroup.GetValue: string;
begin
  Result := GetButtonValue(ItemIndex);
end;

procedure TUniDBRadioGroup.DoSetRemoteValue(AIndex:Integer; Value: string);
var
  OldValue : Integer;
begin
  OldValue := ItemIndex;

  inherited;

  if OldValue = ItemIndex then Exit;

  if FDataLink.DataSource=nil then Exit;

  if FDataLink.DataSet.Active then
  begin
    if not CheckDatasetState(FDataLink, StateValue) then Exit;

    try
      FDataLink.DataSet.Edit;
      FDataLink.Field.Text := GetValue;
    except
      ItemIndex := OldValue;
      SelfUpdating := False;
      raise;
    end;
  end;
end;

function TUniDBRadioGroup.GetDataField: WideString;
begin
  Result := FDataLink.FieldName;
end;

function TUniDBRadioGroup.GetDataSource: TDataSource;
begin
  Result := FDataLink.DataSource;
end;

procedure TUniDBRadioGroup.SetDataField(Value: WideString);
begin
  SetVCLProperty('DataField', Value);

  FDataLink.FieldName := Value;
end;

procedure TUniDBRadioGroup.SetDataSource(Value: TDataSource);
begin
  SetVCLClassProperty('DataSource', Value);

  FDataLink.DataSource := Value;
end;

procedure TUniDBRadioGroup.SetValues(const Value: TStrings);
begin
  FValues.Assign(Value);
end;

function TUniDBRadioGroup.GetField;
begin
  Result := FDataLink.Field;
end;

end.

Üstteki kodu uygalayın. UniGUI kütüphanesini yeniden derlemeniz gerekiyor.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...