小编sav*_*sav的帖子

Python包没有使用pip在virtualenv中安装

我在安装扭曲时遇到问题

pip --version
Run Code Online (Sandbox Code Playgroud)

来自/home/chris/GL/GLBackend/glenv/lib/python2.7/site-packages/pip-1.1-py2.7.egg(python 2.7)的pip 1.1

创建一个虚拟环境

chris@chris-mint ~/GL/GLBackend $ sudo virtualenv -p python2.7 glenv
Run Code Online (Sandbox Code Playgroud)

使用解释器运行virtualenv /usr/bin/python2.7 glenv/bin/python2.7中的新python可执行文件还在glenv/bin/python中创建可执行文件安装distribute ................ .................................................. .................................................. .................................................. .......................完成.安装pip ...............完成.

为了以防万一,我将启用所有权限

chris@chris-mint ~/GL/GLBackend $ sudo chmod -R 777 glenv

chris@chris-mint ~/GL/GLBackend $ source glenv/bin/activate


(glenv)chris@chris-mint ~/GL/GLBackend $ pip freeze
Run Code Online (Sandbox Code Playgroud)

argparse == 1.2.1 distribute == 0.6.24 wsgiref == 0.1.2

twisted在此处未列为已安装

(glenv)chris@chris-mint ~/GL/GLBackend $ sudo pip install twisted
Run Code Online (Sandbox Code Playgroud)

要求已经满足(使用--upgrade升级):twisted in /usr/local/lib/python2.7/dist-packages要求已经满足(使用--upgrade升级):zope.interface> = 3.6.0 in/usr/local/lib/python2.7/dist-packages(来自twisted)需求已经满足(使用--upgrade进行升级):在/usr/local/lib/python2.7/dist-packages中分发(来自zope.interface > = 3.6.0-> twisted)清理......(glenv)chris @ chris-mint~/GL/GLBackend $ pip uninstall twisted无法卸载要求扭曲,未安装存储完整登录/home/chris/.pip/ pip.log

但是当我安装它时它说它已经安装好了.强制安装:

sudo pip …
Run Code Online (Sandbox Code Playgroud)

python pip twisted virtualenv

34
推荐指数
1
解决办法
2万
查看次数

用于将枚举转换为字符串和返回的通用函数

我正在尝试编写将枚举转换为字符串并再次返回的函数.

即:

TConversions = class
    strict private
    public
      class function StringToEnumeration<T:class>(x:String):T;
      class function EnumerationToString<T:class>(x:T):String;
  end;
Run Code Online (Sandbox Code Playgroud)

在我的实施部分

uses
System.TypInfo
;

class function TConversions.StringToEnumeration<T>(x:String):T;
begin
    Result :=  T(GetEnumValue(TypeInfo(T), x));
end;

class function TConversions.EnumerationToString<T>(x:T):String;
begin
    Result := GetEnumName(TypeInfo(T), integer(x));
end;
Run Code Online (Sandbox Code Playgroud)

问题是,枚举不是T:classpascal中的类型.我也不能用T:record.

帕斯卡可以做到这一点吗?

delphi generics pascal

14
推荐指数
3
解决办法
4145
查看次数

如何处理SQL中的日期转换错误?

所以我试图将SQL数据库中的字符串转换为datetime值.

我在这样的表中有一些日期:

23/12/2013 16:34:32
24/12/2013 07:53:44
24/12/2013 09:59:57
24/12/2013 12:57:14
24/12/2013 12:48:49
24/12/2013 13:04:17
24/12/2013 13:15:47
24/12/2013 13:21:02
24/12/2013 14:01:28
24/12/2013 14:02:22
24/12/2013 14:02:51
Run Code Online (Sandbox Code Playgroud)

不幸的是,它们被存储为字符串

我想将它们转换为日期时间

SELECT CONVERT(datetime, analysed, 103 )
FROM OIL_SAMPLE_UPLOAD
Run Code Online (Sandbox Code Playgroud)

但是,当我运行查询时,我收到此消息

将varchar数据类型转换为日期时间数据类型会导致超出范围的值.

大概是因为一些价值观形成不好(虽然我还没有发现其中的任何一个)

如果某些值不转换就可以了,我只需要一种处理这种情况的方法.

类似于ISNULL(CONVERT(datetime,analyze,103))之类的东西会很好,除非转换函数在失败时不返回NULL.

sql t-sql string error-handling type-conversion

12
推荐指数
2
解决办法
4万
查看次数

在delphi中测试泛型的类型

我想用一些方法在delphi中编写一个函数,如下所示

procedure Foo<T>;
begin
    if T = String then
    begin
        //Do something
    end;

    if T = Double then
    begin
        //Do something else
    end;
end;
Run Code Online (Sandbox Code Playgroud)

即:我希望能够根据泛型类型做不同的事情

我尝试过使用TypeInfo,System但这似乎适合于对象而不是泛型类型.

我甚至不确定帕斯卡是否可行

delphi generics pascal delphi-xe6

9
推荐指数
2
解决办法
1930
查看次数

Delphi中有没有办法为按钮事件分配匿名方法?

我想知道Delphi中是否有一种方法可以为表单控件事件分配匿名方法.

例如:

Button1.OnClick := procedure (Sender: TObject) begin ShowMessage('') end;
Run Code Online (Sandbox Code Playgroud)

当然这给了我一个错误

[dcc32错误] Control.Controller.pas(51):E2009不兼容的类型:'方法指针和常规程序'

这是因为该方法必须属于一个对象,但它不再是匿名的.

也许有一些解决方法

delphi events anonymous-function

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

在pascal中动态分配匿名函数

我希望能够在pascal中动态生成弹出菜单.

我还希望能够为每个菜单项动态分配OnClick处理程序.

这是我习惯于在C#中做的事情,这是我在pascal中的尝试.

菜单项onClick事件处理程序需要属于一个对象(of Object),所以我为此创建一个容器对象.

这是我的代码:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TFoo = class
    public
      Bar : String;
      Val : Integer;
  end;

  TNotifyEventWrapper = class
    private
      FProc: TProc<TObject>;
      I : Integer;
    public
      constructor Create(Proc: TProc<TObject>);
    published
      procedure Event(Sender: TObject);
  end;

var
  Form1: TForm1;
  NE : TNotifyEventWrapper;

implementation

{$R …
Run Code Online (Sandbox Code Playgroud)

delphi anonymous-function delphi-xe6

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

在delphi中打印到非默认打印机

我想使用Delphi将打印作业发送到打印机.理想情况下,我希望能够在不让用户从打印对话框中选择打印机的情况下执行此操作.

我希望能够使用Windows默认打印机以外的打印机.

我试过用打印机名称设置打印机:

Vcl.Printers.Printer.PrinterIndex := Vcl.Printers.Printer.Printers.IndexOf('My Printer Name');
Run Code Online (Sandbox Code Playgroud)

但是,当我打印时,它将恢复使用默认打印机

delphi

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

传递函数而不是调用它(Delphi)

所以我在Delphi中有一个表单

TFrmMainForm = class(TForm, IFrmMainFormInterface)
  public
    procedure Display(Sender:TObject); 
end;
Run Code Online (Sandbox Code Playgroud)

界面是

IFrmMainFormInterface = interface
  procedure Display(Sender:TObject);
end;
Run Code Online (Sandbox Code Playgroud)

另一堂课

TMainFormViewModel = class
    strict private
      fTimer : TTimer;
      function GetOnTimer : TNotifyEvent;
      procedure SetOnTimer(timerEvent : TNotifyEvent);
    public
      property OnTimer : TNotifyEvent read GetOnTimer write SetOnTimer;
end;

implementation

function TMainFormViewModel.GetOnTimer : TNotifyEvent;
begin
    Result := fTimer.OnTimer;
end;

procedure TMainFormViewModel.SetOnTimer(timerEvent : TNotifyEvent);
begin
    fTimer.OnTimer := timerEvent;
end;
Run Code Online (Sandbox Code Playgroud)

我有一个Form MainForm的实例和视图模型类MainFormViewModel

我想试试

MainFormViewModel.OnTimer := IFrmMainFormInterface(MainForm).Display
Run Code Online (Sandbox Code Playgroud)

问题是这给我一个错误信息

实际参数不够

我相信这是因为delphi试图调用显示功能而不是将其分配给OnTimer事件.我不知道如何解决这个问题,我尝试使用@运算符但没有成功.

编辑

我应该补充一点,MainForm在这个函数中被声明为

procedure Initialise<T:Class, IFrmMainFormInterface>(MainForm …
Run Code Online (Sandbox Code Playgroud)

delphi pascal function

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

Delphi Pascal XE4编译器错误?

我想知道我是否找到了Embarcadero编译器错误...

问题看起来与泛型有关.

这是我的源代码

unit u_DateCount;

interface

uses
  SysUtils,
  u_JavaScriptable
  ;

type
  TDateCount = class (TJavaScriptable)
    strict private
    public
      NoOfSamples : Integer;
      TheDate : TDate;
      function ToString():String; override;
  end;

implementation

function TDateCount.ToString():String;
var
    myYear, myMonth, myDay : Word;
begin
    DecodeDate(TheDate, myYear, myMonth, myDay);
    Result := Format('[new Date(%d, %d ,0), %d]', [myYear, myMonth, NoOfSamples]);
end;

end.
Run Code Online (Sandbox Code Playgroud)
unit u_Javascriptable;

interface

type
  TJavaScriptable = class
    strict private
    public
      function ToString:String; override;
  end;

implementation

function TJavaScriptable.ToString:String;
begin
    Result := '';
end;

end.
Run Code Online (Sandbox Code Playgroud)
unit u_LineChart;

interface …
Run Code Online (Sandbox Code Playgroud)

delphi generics delphi-xe4

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

在pascal中动态分配匿名通用函数

我有以下类层次结构

类

我希望能够动态分配适用于这两种类型的对象进行操作的匿名方法TBTC.

所以这是一个简单的人为例子:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TNotifyEventWrapper = class
    private
      FProc: TProc<TObject>;
    public
      constructor Create(Proc: TProc<TObject>);
    published
      procedure Event(Sender: TObject);
    end;

  IA = interface
    procedure Foo;
  end;

  TA = class(TInterfacedObject)
    procedure Foo;
  end;

  TB = class(TA, IA)
    procedure Foo;
  end; …
Run Code Online (Sandbox Code Playgroud)

delphi generics interface anonymous-function

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