在我的应用程序中,使用XE7 for Android/iOS开发,我有一个用于扫描条形码的表单.找到条形码后,我的应用程序会验证它是否是可接受的条形码.以下教程:http://www.fmxexpress.com/qr-code-scanner-source-code-for-delphi-xe5-firemonkey-on-android-and-ios/
目前我在Android上进行测试,我能够集成扫描和读取条形码,但是当从共享的查找条形码的Activity返回时,'onBarCode'事件不会触发.相同的代码与以前版本的Rad Studio(XE4,XE5,XE6)运行良好,但现在在XE7中却没有.
以下是一些代码片段:
...
begin
Scanner := TAndroidBarcodeScanner.Create(true);
Scanner.OnBarCode := BarcodeHandler;
Scanner.Scan;
end;
procedure TmScannerForm.BarcodeHandler(Sender: TAndroidBarcodeScanner;
BarCode: String);
begin
text1.Text := Barcode;
memo1.PasteFromClipboard;
AddBarcode(BarCode, true);
end;
Run Code Online (Sandbox Code Playgroud)
AddBarCode甚至是我用来验证和添加条形码到列表,但我没有包括它,因为该代码不是问题 - 它甚至没有触发.Text1.text:= Barcode和memo1.paseFromClipboard在他们的验证中,偶数也没有解雇.我可以确认正在读取条形码,因为如果我点击并手动粘贴,条形码会显示.
为什么这不像在以前版本的Rad Studio中那样在XE7上运行?
我最近安装了Delphi XE7并且一直在添加我的第三方组件集.我的开发机器上也有Delphi 7,XE4和XE6.运行JVCL 3.48安装时,我可以选择安装或更新7,XE 4和XE 6但不是XE 7.我需要做什么才能拿到这个版本?
非常感激
我目前正在尝试找到最好的(*)方式让两个线程交替运行并让它们互相等待.
(*)具有低CPU成本的快速的最佳组合
到目前为止,我找到了三种方法,我将它放在一些演示应用程序中,以显示我发现的问题.
使用遵循经典等待/脉冲模式的TMonitor由于所有锁定而执行得不是很好(根据SamplingProfiler在这些函数中大部分时间都会消耗).我尝试使用Windows事件(SyncObjs.TEvent),但它执行类似(即坏).
使用调用TThread.Yield的等待循环表现最佳,但显然会像疯狂一样烧掉CPU周期.如果切换发生得非常快,那无关紧要,但是当线程实际等待时会受到伤害(你可以在演示中看到).
使用TSpinWait表现很好(如果不是这三个中最好的),但只有在切换发生得非常快的情况下.由于TSpinWait的工作方式,切换性能越差,性能越差.
由于多线程不是我的优势之一,我想知道是否有这些方法的某种组合或一些完全不同的方法来在两种情况下实现良好的性能(快速和慢速切换).
program PingPongThreads;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Classes,
Diagnostics,
SyncObjs,
SysUtils;
type
TPingPongThread = class(TThread)
private
fCount: Integer;
protected
procedure Execute; override;
procedure Pong; virtual;
public
procedure Ping; virtual;
property Count: Integer read fCount;
end;
TPingPongThreadClass = class of TPingPongThread;
TMonitorThread = class(TPingPongThread)
protected
procedure Pong; override;
procedure TerminatedSet; override;
public
procedure Ping; override;
end;
TYieldThread = class(TPingPongThread)
private
fState: Integer;
protected
procedure Pong; override;
public
procedure Ping; override;
end;
TSpinWaitThread = class(TPingPongThread) …Run Code Online (Sandbox Code Playgroud) 我找到了各种关于如何使TWebBrowser使用代理的例子(如202.8.128.5:8080).但是,所有这些示例都是为所有正在运行的TWebBrowser实例全局更改代理.我有两个例子.如何为每个浏览器设置不同的代理?
我是Delphi的新手,拥有C++背景,并试图弄清楚如何实现智能指针.我遇到了以下帖子,我试图将其作为我自己的起点:Delphi - 智能指针和泛型TList
但是我无法使用Delphi XE7编译以前的代码(编译器错误在代码中显示为注释).如果有人真正解释了代码的逻辑,我也会非常感激(最初我想将该类用作实用程序类中的一个drop,但现在我想了解实际发生的情况).我隐约明白,因为智能指针实现继承自TInterfacedObject,所以它是引用计数但超出此范围的任何东西对我来说都没有意义:)
unit SmartPointer;
interface
uses
SysUtils, System.Generics.Collections;
type
ISmartPointer<T> = reference to function: T;
// complains ISmartPointer<T> expecting an interface type
TSmartPointer<T: class, constructor> = class(TInterfacedObject,ISmartPointer<T>)
private
FValue: T;
public
constructor Create; overload;
constructor Create(AValue: T); overload;
destructor Destroy; override;
function Invoke: T;
end;
implementation
{ TSmartPointer<T> }
constructor TSmartPointer<T>.Create;
begin
inherited;
FValue := T.Create;
end;
// complains: overload procedure TSmartPointer.Create must be marked with the overload directive
constructor TSmartPointer<T>.Create(AValue: T);
begin
inherited Create;
if …Run Code Online (Sandbox Code Playgroud) 看着调用堆栈我刚才注意到了这一点:

请注意Opt.out顶部.
只是好奇,什么Opt.out意思?
这是我要介绍的片段:
function BinaryEquals(Left, Right: pointer; Size: integer): boolean;
....
{$IFDEF CPUX64}
asm
....
sub r8,4
@loop1:
inc R8
Run Code Online (Sandbox Code Playgroud) 我有一个函数将TBitmap(我绘制)转换为TPngImage,然后将其保存为流,因此其他方法可以使用它.使用Png是因为它为报告输出创建了较小的图像(excel,html).问题是SaveToStream似乎花费了太多时间,比将TBitmap转换为TPngImage或使用带有png的TStream多15倍.这是代码:
var
BitmapImage: TBitmap;
PNGImage: TPngImage;
PngStream: TStream;
begin
// draw on BitmapImage
...
PNGImage := TPngImage.Create;
PNGStream := TMemoryStream.Create;
Try
PNGImage.Assign(BitmapPicture.Bitmap); // Step 1: assign TBitmap to PNG
PNGImage.SaveToStream(PNGStream); // Step 2: save PNG to stream
WS.Shapes.AddPicture(PNGStream,PNGImage.Width,PNGImage.Height); // Step 3: Add PNG from Stream to Excel
finally
PNGImage.Free;
PNGStream.Free;
end;
...
Run Code Online (Sandbox Code Playgroud)
这是用70000张图像测试的,这里是时间:
步骤1:7秒
第2步:93秒
第3步:6秒
为什么保存到Stream这么慢?有什么建议可以优化吗?
使用Delphi XE7
编辑
这是带有简单bmp的示例(MCVE),它将转换为PNG,然后保存到流中.只是为了另一个验证,我添加了SaveToFile,当然需要更长时间,但它保存到磁盘,所以我认为可以接受.
img1.bmp为49.5KB,保存的PNG为661字节.链接到img1.bmp = http://www.filedropper.com/img1_1
TMemoryStreamAccess = class(TMemoryStream)
end;
procedure TForm1.Button1Click(Sender: TObject);
var BitmapImage:TBitmap;
PNGImage:TPngImage;
PNGStream:TMemoryStream;//TStream;
i,t1,t2,t3,t4,t5,t6: Integer;
vFileName:string;
begin
BitmapImage:=TBitmap.Create; …Run Code Online (Sandbox Code Playgroud) 考虑这个测试应用:
function RemoveDuplicates(const Input: IEnumerable<Integer>): IEnumerable<Integer>;
begin
// How to implement this function?
end;
var
Enumerable: IEnumerable<Integer>;
UniqueEnumerable: IEnumerable<Integer>;
begin
Enumerable := TCollections.CreateList<Integer>([1, 1, 2, 3, 3, 3, 4]);
UniqueEnumerable := RemoveDuplicates(Enumerable);
UniqueEnumerable.ForEach(
procedure(const I: Integer)
begin
WriteLn(I);
end);
ReadLn;
end.
Run Code Online (Sandbox Code Playgroud)
如何实现该RemoveDuplicates功能(这nub在Haskell中调用)?
我正在使用Delphi XE7,我无法将对象转换为JSON.我可以得到一些对象来回馈我认为合适的JSON,例如TTestObject:
{"Test":{"Field":"TestField","Operation":"TestOperation","values":
["Value1","Value2","Value3","Value4"]}}
Run Code Online (Sandbox Code Playgroud)
JOBJ:= TJSONObject.Create;
JOBJ.AddPair('Test', ATestObject.JSONObj);
memo1.Lines.Add(JObj.ToJSON);
JOBJ.Free;
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试从具有对象属性的对象中获取JSON时,我会获得带有\字符的JSON .
{"Exceptions":{"TestObject1":"
{\"Mode\":\"0\",\"Value\":\"100.50\",\"Days\":\"10\"}","TestObject2":"
{\"Mode\":\"0\",\"Days\":\"0\",\"UnitsSold\":\"
...
Run Code Online (Sandbox Code Playgroud)
是什么造成的?
我想创建一个启动屏幕(在主窗体之前)将显示x秒但我不想延迟使用x秒创建主窗体.
所以,我创建了启动画面窗体,创建主窗体然后在x秒后关闭启动窗体.
据我所知,使用CreateForm创建的第一个表单是主表单.这是正确的吗?
begin
Application.Initialize;
Application.MainFormOnTaskbar := FALSE;
Application.Title := AppName;
frmSplash:= TfrmSplash.Create(NIL); <----- not main form??
Application.CreateForm(TfrmMain, frmMain); <----- main form??
frmMain.LateInitialization;
frmMain.show;
Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)
关闭启动窗体
启动画面有一个TTimer.计时器在启动窗体中执行一些动画,在x秒后它关闭窗体:
procedure TfrmSplash.CloseSplashForm;
begin
Timer.Enabled:= FALSE;
Close; <-- I do see the program reaching this point
end;
Run Code Online (Sandbox Code Playgroud)
但是,应用程序在关闭时泄漏mem:
5 - 12 bytes: TMoveArrayManager<System.Classes.TComponent> x 4, Unknown x 2
13 - 20 bytes: TObservers x 1, TList x 3, Unknown x 3
21 - 36 bytes: TComponent.GetObservers$942$ActRec x 1, TPen x 2, …Run Code Online (Sandbox Code Playgroud)