小编Geo*_*rey的帖子

将Delphi 2007中的事件处理程序分配给表单上的所有控件

我正在尝试创建一小部分软件,以便拖放一下.我开始只动态创建TButtons,它工作正常.

但是,在概括功能时,由于基类TControl的OnDragDrop和OnMouseDownEvent的"受保护"状态,我遇到了问题.

procedure TForm1.FormDragDrop(Sender, Source: TObject; X, Y: Integer);
  var
    newControl: TControl;
    selClass: TControlClass;
    ctlName: string;
    selItem: string;
  begin
    if TControl(Sender).Parent = Self then
    begin
      with TWinControl(Source) do
      begin
        Left:= X;
        Top:= Y;
        EndDrag(True); {drop the control}
      end;
    end
    else begin
      selItem:= TypeList.Items[TypeList.ItemIndex];
      selClass:= TControlClass(GetClass(selItem));

      newControl:= selClass.Create(Self);
      newControl.Parent:= Self;

      ctlName:= newControl.ClassName + IntToStr(GetControlCount(selClass));
      Delete(ctlName, 1, 1); {Remove 'T' from name}

      newControl.Name:= ctlName;
      newControl.Left:= X;
      newControl.Top:= Y;

      { TODO : assign events onDragDrop and onMouseDown}
      (*
      newControl.OnMouseDown:= @ControlMouseDown;
      newControl.OnDragDrop:= @FormDragDrop;
      *) …
Run Code Online (Sandbox Code Playgroud)

delphi oop

1
推荐指数
1
解决办法
493
查看次数

参数化查询为String

在我的项目中,我需要记录针对我的数据库执行的所有查询.作为示例,我们可以在此处使用人员用户数据.在该类中,我有一个函数生成带有如下参数的命令:

Public Function SQLUpdate(ByVal conn As SqlClient.SqlConnection) As SqlClient.SqlCommand Implements IDbConnected.SQLUpdate
    Dim sqlstatement As String = "UPDATE Persons SET Active=@act, Abbreviation=@abbr, FirstName=@first, LastName=@last, " & _
                                 "Birthday=@bday, Email=@email,Tel=@tel, Fax=@fax, Registered=@reg, Admin=@adm"
    sqlstatement &= " WHERE ID=" & Me.ID
    Dim comm As New SqlClient.SqlCommand(sqlstatement, conn)
    With comm.Parameters
        .Add("@act", SqlDbType.Bit).Value = Me.Active
        .Add("@abbr", SqlDbType.VarChar).Value = Me.Abbreviation
        .Add("@first", SqlDbType.VarChar).Value = Me.FirstName
        .Add("@last", SqlDbType.VarChar).Value = Me.LastName
        .Add("@bday", SqlDbType.SmallDateTime).Value = Me.Birthday
        .Add("@email", SqlDbType.VarChar).Value = Me.Email
        .Add("@tel", SqlDbType.VarChar).Value = Me.Telephone
        .Add("@fax", SqlDbType.VarChar).Value = Me.Fax
        .Add("@reg", SqlDbType.Bit).Value …
Run Code Online (Sandbox Code Playgroud)

.net sql vb.net

0
推荐指数
1
解决办法
141
查看次数

标签 统计

.net ×1

delphi ×1

oop ×1

sql ×1

vb.net ×1