大多数Pascal控件结构对我有意义,例如:
for ... do {statement};
if (condition) then {statement};
while (condition) do {statement};
Run Code Online (Sandbox Code Playgroud)
其中{statement}是单个语句或begin ... end块.我有一个问题:
repeat {statement-list} until (expression);
try {statement-list} except {statement-list} end;
Run Code Online (Sandbox Code Playgroud)
重复并尝试具有相同的通用结构,只接受单个语句或开始 ... 结束块,而不是具有未正式阻止开头和结尾的语句列表,这不是更好吗?
作为一般规则,我通过利用Const(无类型)参数而不是硬编码类型来使用指针时绕过了许多经典设计陷阱.这使我在执行高级图形功能时具有速度优势,同时将技术细节留给编译器.它还使得在Delphi和Free Pascal中使用相同的代码变得容易,只需要进行很少的更改.但是,由于Embarcadero关于Delphi演变的vauge声明以及它的upcomming安全模型,我已经开始质疑这一点.
例如,concider以下示例:
Type TSomeDataProc = procedure (const aInput;var aOutput) of Object;
(* Convert 8-bit pixel to 16-bit pixel *)
Procedure TMyClass.ProcessSomeData08x565(Const aInput;var aOutput);
var r,g,b: Byte;
Begin
FPalette.ExportTriplets(Byte(aInput),r,g,b);
Word(aOutput):=(R SHR 3) SHL 11 or (G SHR 2) SHL 5 or (B SHR 3);
End;
(* Convert 16-bit pixel to 24-bit pixel *)
Procedure TMyClass.ProcessSomeData565x888(Const aInput;var aOutput);
Begin
With TRGBTriple(aOutput) do
Begin
rgbtRed:=(((word(aInput) and $F800) shr 11) shl 3);
rgbtGreen:= (((word(aInput) and $07E0) shr 5) shl 2);
rgbtBlue:= ((word(aInput) and …Run Code Online (Sandbox Code Playgroud) 我尝试使用Delphi的匿名方法语法:
type
fun = reference to function(): Integer;
Run Code Online (Sandbox Code Playgroud)
Fpc显示语法错误:
Error: Identifier not found "reference"
Run Code Online (Sandbox Code Playgroud)
什么是免费Pascal相当于Delphi的匿名方法,如果有的话?
任何人都可以帮我解决Delphi中一些裸骨,旧学校3D方法的例子吗?不使用openGL或firemonkey或任何外部库(vanilla canvas编码).我想要做的是能够围绕共同的原点旋转X个点.从我以往的记忆中,你从右边减去(在3d点上),使origo始终为0,0 - 然后执行计算,最后添加左/上像素偏移量以获得实际的屏幕位置.
我正在寻找的是一套小型的临时例程,ala:
使用这些功能,创建旧的"旋转三维立方体"(8分)应该相当容易.
还有,有没有找出可见的"面孔"的功能?如果我想要一个填充的矢量立方体,那么我想我需要提取可见区域(基于距离/重叠?),然后将其绘制为X个填充多边形?毫无疑问,这些必须按深度排序,以免出现问题.
例如:
欢迎任何帮助!
我们有一个充满了定制组件的项目,现在在Lazarus和Delphi中工作.
我正在考虑代码接口,但我对它们并不熟悉.我想知道的是:Delphi和Lazarus接口的实现细微差别是什么?有什么我应该特别注意的吗?我需要编写真正不同的代码吗?
背景说明:我认为组件可以从接口中受益,或者至少,我将从中学到更多.例如,其中一个组件使用串行端口与许多不同的硬件进行通信.但是用户应该只使用我们的组件来创建应用程序.因此,我们为每个从基类继承的硬件提供了组件和一个类.在运行时,我们在组件内创建特定的类.
不确定最后的解释是否需要,但如果你们有人需要,我可以写更多.
当我尝试使用包含撇号的值执行下面的PostgreSQL查询时,我遇到了我的第一个sql转义错误(它已经过期了).O'Brien,使用FreePascal和Lazarus
SQL.Add(format('select * from zones where upper(zn_name) >= %s and upper(zn_name) < %s order by zn_name',[sQuote(zoneMin), sQuote(zoneMax)]));
Run Code Online (Sandbox Code Playgroud)
在上面的查询中,SQuote是一个用单引号包装字符串的函数.是否有一些标准库用于清理Lazarus/FreePascal或Delphi的SQL查询参数?
使用ToBytes方法(见下文)将AnsiString的硬类型转换替换为TBytes(字符串数组)后,Delphi报告没有内存泄漏 - 但是,如果将TBytes值传递给具有a的方法,则Free Pascal 2.6.2会显示泄漏类型的参数Pointer.
以下代码泄漏内存:
program project1;
{$mode delphi}
uses
SysUtils;
function ToBytes(const AValue: AnsiString): TBytes;
begin
SetLength(Result, Length(AValue)); // <-- leak (ine 10)
if Length(AValue) > 0 then
Move(AValue[1], Result[0], Length(AValue));
end;
procedure Send(P: Pointer);
begin
end;
begin
Send(ToBytes('test'));
SetHeapTraceOutput('heaptrace.log');
end.
Run Code Online (Sandbox Code Playgroud)
内存泄漏报告:
Call trace for block $001C5CC0 size 12 $00401586 TOBYTES, line 10
of project1.lpr $00401622 main, line 21 of project1.lpr
Run Code Online (Sandbox Code Playgroud)
如果我将Send方法更改为采用TBytes类型的参数,则内存泄漏将消失.
这是我的问题:我想创建一个记录类型,其中在变体记录的情况下,一些(但不是全部)将具有某个字段.根据维基,这是完全合法的.然而,当我尝试编译以下代码时:
program example;
{$mode objfpc}{$H+}
uses sysutils;
type
maritalStates = (single, married, widowed, divorced);
TPerson = record
name: record
first, middle, last: string;
end;
sex: (male, female);
dob: TDateTime;
case maritalStatus: maritalStates of
single: ( );
married, widowed: (marriageDate: TDateTime);
divorced: (marriageDate, divorceDate: TDateTime;
isFirstDivorce: boolean)
end;
var
ExPerson: TPerson;
begin
ExPerson.name.first := 'John';
ExPerson.name.middle := 'Bob';
ExPerson.name.last := 'Smith';
ExPerson.sex := male;
ExPerson.dob := StrToDate('05/05/1990');
ExPerson.maritalStatus := married;
ExPerson.marriageDate := StrToDate('04/01/2015');
end.
Run Code Online (Sandbox Code Playgroud)
编译失败,出现以下错误:
$ fpc ex.pas
Free …Run Code Online (Sandbox Code Playgroud) 试图将Delphi库移植到Android.免费Pascal支持Android/ARM - 可以使用Windows的预构建编译器.但是,Android NDK现在也支持MIPS和x86.FPC支持者的状态如何?目前,我的项目或多或少与CPU无关 - 本机位是为所有四种支持的体系结构构建的.不想放手.
我不是在Pascal的完整Android开发周期之后 - 只是一个没有I/O的算法库.我尝试用p2c将其翻译成C语言,但译者对来源进行了扼流.
我是否应该尝试使用Linux为相关CPU构建交叉编译器,然后链接到NDK库?
编辑:我已经从Android分支的源代码构建了针对Intel/Linux的交叉编译器.它工作,除了你必须调用ppcross386编译,而不是fpc.看起来,后者忽略-Tlinux选项并调用Intel/Win32编译器.
EDIT2:对makefile和源进行少量更改,MIPS交叉编译器构建.但是,随着构建转移到跨CPU RTL,它几乎立即出错.
freepascal ×10
delphi ×6
fpc ×3
lazarus ×2
pascal ×2
3d ×1
64-bit ×1
android ×1
android-ndk ×1
closures ×1
compiler-bug ×1
components ×1
graphics ×1
interface ×1
lambda ×1
memory-leaks ×1
postgresql ×1
record ×1
repository ×1
sql ×1
variant ×1