Page 1 of 1

SRVLabel Implementation

Posted: Tue Nov 10, 2009 1:50 am
by mwilems1
OK. This is a continuation of the conversation from http://www.trichview.com/forums/viewtop ... 3924#13924 "Label Overlaps Text" but centering on SRVControl usage.

I am trying to implement SRVLabel, SRVEdit, and SRVCheckBox for data retrieval and input. Currently I am working on data retrieval and display.

Item 1: create a subclass of SRVLabel with additional properties to store database table and field properties. Each DBSRVEdit is also stored with a "primary record type" which identifies a parent record. Related data in the database can be identified from the primary record. This is relatively easy.

Item 2: create a completely text based object (no database interaction) that will display a few dilimited segments and when a user clicks on a segment, the control object is replaced with the text segment; such as "Thank you for contacting our support department."

For Item 2 I have been trying to use SRVLabel. So far this has been difficult but successful. However, the Label will not go beyond the end of a line. I am assuming this is a limitation of the TCaption object.

I have tried tracing the object definitions back and am still working on it. My knowledge of Delphi/Win32 programing is good, but not great and some of this is beyond my current knowledge. I've only been working with Delphi since April. My history is C, C++, Java. Man, I wish I was smarter!!! :?

The Problem:
I'm looking for a way to display long text strings that will wrap lines (a.k.a. continue beyond the end of the line to the next) with an object that will respond to a click with x/y coordinates so I can identify a specific text segment dimilited by a set of characters such as "||" (two vertical bars).

And; I have 36 hours to get this accomplished!!!! :shock:

Posted: Tue Nov 10, 2009 2:32 am
by mwilems1
Also,

I tried using AutoSize and it didn't work. The objects won't resize. Here is my code:

Code: Select all

procedure TtemplateForm.InsertClickTextFieldClick(Sender: TObject);
var
  fieldPopup: TdocumentFieldInsPop;
  ClickTextField: TDocumentClickText;
begin
  if ValidPrimaryRecord then
  begin
    fieldPopup := TDocumentFieldInsPop.CreatePopUp(Self,ftClickText);
    if fieldPopup.Execute then
    begin
      ClickTextField := TDocumentClickText.Create(SRichViewEdit1,fieldPopup.ClickTextMemo.Text);
      ClickTextField.AutoSize := true;
      ClickTextField.OnClick := ControlOnClick;
      ClickTextField.OnMouseMove := ControlOnMouseMove;
      ClickTextField.OnMouseDown := ControlOnMouseDown;
      ClickTextField.OnMouseEnter := ControlOnMouseOver;
      ClickTextField.OnMouseLeave := ControlOnMouseOut;
      ClickTextField.ForegroundColor := clWhite;
      ClickTextField.BackgroundColor := clBlack;
      SRichViewEdit1.RichViewEdit.InsertControl(TRVAnsiString('clicktext'+IntToStr(SRichViewEdit1.RichViewEdit.ItemCount)),
        ClickTextField,rvvaAbsMiddle);
    end;
  end;
end;

procedure TtemplateForm.ControlOnClick(Sender: TObject);
begin
   SRichViewEdit1.RichViewEdit.SelectControl(TControl(sender));
end;

procedure TtemplateForm.ControlOnStartDrag(Sender: TObject;
  var DragObject: TDragObject);
begin
  SRichViewEdit1.RichViewEdit.SelectControl(TControl(Sender));
  Screen.Cursor := crDrag;
  SRichViewEdit1.RichViewEdit.BeginOleDrag;
end;

procedure TtemplateForm.ControlOnMouseOver(Sender: TObject);
begin
  Screen.Cursor := crHandPoint;
end;

procedure TtemplateForm.ControlOnMouseOut(Sender: TObject);
begin
  Screen.Cursor := crDefault;
end;

procedure TtemplateForm.ControlOnMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then begin
    SRichViewEdit1.RichViewEdit.SelectControl(TControl(Sender));
    ClickedControl := Sender;
    ClickPoint := Point(X, Y);
  end;
end;

procedure TtemplateForm.ControlOnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  if (ssLeft in Shift) and (ClickedControl=Sender) and
    (Sqr(ClickPoint.X-X)+Sqr(ClickPoint.Y-Y)>10) then
    SRichViewEdit1.RichViewEdit.BeginOleDrag;
end;
TDocumentClickText is just a subclass of TSRVLabel with additional properties for TableName, FieldName, PrimaryRecord, etc...

Much of the event code is copied from examples. Only the mouse settings are working.

If I add:

Code: Select all

SRichViewEdit1.RichViewEdit.SetCurrentItemExtraIntProperty(rvepResizable,1,true);
Resize works.

I also need to make inserted controls resizable and moveable when the "template" is reloaded. I don't see a way to get an ItemNumber from a control so I can use "SetItemExtraIntPropertyEd". I do cycle through each component to set event handlers when I load the DBSRVE. Is there a simple way to either get the ItemNumber or select the control so it is the CurrentItem?

Posted: Tue Nov 10, 2009 9:08 am
by Sergey Tkachenko
Unfortunately, implementing text drawing so that text will be scaled proportionally (to support WYSIWYG) is not a trivial task. You can see the problem in our labels - they are because they use simple WinAPI text drawing functions. We will fix these problems in the next update.

Consider using normal TRichView text instead, with tags and protection options. For rectangular text area, you can use a table.

Posted: Wed Nov 11, 2009 10:39 pm
by proxy3d
See also: Demos\Controls\SRVControls\

Example:

Code: Select all

procedure TForm.FormCreate(Sender: TObject);
begin
  SRV.LoadRVF('SRVControls.rvf');
  SRV.ProcessControls;
end;

procedure TForm.SRVCheckControl(Sender: TSRichViewEdit; AControl: TControl);
begin
  If AControl is TSRVLabel then
    TSRVLabel(AControl).OnClick := FormOnClick;
end;
After call ProcessControls, SRV for all Control (in the document) calls OnCheckControl.

Event see:
SRV.OnCheckControl (Sender: TSRichViewEdit; AControl: TControl);

For reception of event from Control it is possible to use:
SRV.OnMessageControl (Sender: TSRichViewEdit; AControl: TControl; var Message: TMessage);

Current Control in a caret position: SRV.CurControl : TControl