我已经创建了一个从Delphi/Lazarus应用程序加载的轮廓检测共享库.主应用程序将指针传递给位图,该指针由库内的函数处理.
这是库中的功能.参数"img"是指向我的位图的指针.
extern "C" {
void detect_contour(int imgWidth, int imgHeight, unsigned char * img, int &x, int &y, int &w, int &h)
{
Mat threshold_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);
/// Load source image and convert it to gray
Mat src(imgHeight, imgWidth, CV_8UC4);
int idx;
src.data = img;
/// Convert image to gray and blur it
cvtColor( src, src_gray, CV_BGRA2GRAY );
blur( src_gray, src_gray, Size(10,10) );
/// Detect …Run Code Online (Sandbox Code Playgroud) Delphi允许3个版本的Copy功能:
function CopyTest(const S: string): string;
begin
Result:= Copy(S, 1, 5);
Result:= Copy(S, 1);
// Result:= Copy(S); // not allowed for strings, allowed for dyn arrays
end;
Run Code Online (Sandbox Code Playgroud)
FreePascal似乎只编译第一个(3-arg)版本; 对于其他人我有编译时错误
Error: Wrong number of parameters specified for call to "$fpc_ansistr_copy"
Run Code Online (Sandbox Code Playgroud)
我是否遗漏了一些FPC编译器开关或CopyFree Pascal中没有过载?
我正在从Java程序中调用来自Delphi编译的*.so文件的函数.经过一些研究,似乎JNA是他的出路.在深入研究一些复杂的Delphi代码之前,我正在尝试使用一些"Hello World"代码,但是在获取Delphi函数返回的字符串时遇到了麻烦.
Delphi代码(helloworld.pp):
library HelloWorldLib;
function HelloWorld(const myString: string): string; stdcall;
begin
WriteLn(myString);
Result := myString;
end;
exports HelloWorld;
begin
end.
Run Code Online (Sandbox Code Playgroud)
我使用" fpc -Mdelphi helloworld.pp " 从命令行编译它,生成libhelloworld.so.
现在我的Java类:
import com.sun.jna.Library;
import com.sun.jna.Native;
public class HelloWorld {
public interface HelloWorldLibrary extends Library {
HelloWorldLibrary INSTANCE = (HelloWorldLibrary) Native.loadLibrary("/full/path/to/libhelloworld.so", HelloWorldLibrary.class);
String HelloWorld(String test);
}
public static void main(String[] args) {
System.out.println(HelloWorldLibrary.INSTANCE.HelloWorld("QWERTYUIOP"));
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个Java代码时,我得到:
# A fatal error has been detected by the Java Runtime Environment:
#
# …Run Code Online (Sandbox Code Playgroud) 以下代码在我的系统中按预期运行,但我不确定P变量是否保证在MyArray[0]更改为新值后具有相同的值.
procedure Test;
var
MyArray: array of string;
P : PChar;
begin
SetLength(MyArray, 2);
MyArray[0] := 'ABCD';
MyArray[1] := '1234';
// Is P guaranteed to have the same value all the time?
P := PChar(MyArray[0]);
MyArray[0] := MyArray[1];
MyArray[1] := P;
WriteLn(MyArray[0]);
WriteLn(MyArray[1]);
end;
Run Code Online (Sandbox Code Playgroud) 我现在正在尝试探索pascal.我遇到了一些编译器错误.我写了一个if else if语句,如下所示:
if ((input = 'y') or (input = 'Y')) then
begin
writeln ('blah blah');
end;
else if ((input = 'n') or (input = 'N')) then
begin
writeln ('blah');
end;
else
begin
writeln ('Input invalid!');
end;
Run Code Online (Sandbox Code Playgroud)
它在第一次给我一个错误else:
";" 预期,但"ELSE"发现
我找了很多关于if语句的教程,他们就像我一样:
if(boolean_expression 1)then
S1 (* Executes when the boolean expression 1 is true *)
else if( boolean_expression 2) then
S2 (* Executes when the boolean expression 2 is true *)
else if( boolean_expression 3) then
S3 (* Executes …Run Code Online (Sandbox Code Playgroud) Delphi和FPC BASM之间的另一个差异:
program PopTest;
{$IFDEF FPC}
{$mode delphi}
{$asmmode intel}
{$ELSE}
{$APPTYPE CONSOLE}
{$ENDIF}
var
B: LongWord;
procedure Pop(A: LongWord; var B: LongWord);
asm
PUSH EAX
POP [EDX]
end;
begin
Pop(5, B);
Writeln(B);
Readln;
end.
Run Code Online (Sandbox Code Playgroud)
这个32位代码在Delphi XE中按预期工作,并在FPC中产生访问冲突(2.6.4)
调试显示POP指令(在FPC编译器中)弹出一个单词而不是预期的双字,从而破坏堆栈和过程的返回地址.解决方案是
procedure Pop(A: LongWord; var B: LongWord);
asm
PUSH EAX
POP DWORD [EDX]
end;
Run Code Online (Sandbox Code Playgroud)
这实际上是更好的代码,因为它消除了参数大小歧义.
错误与否?
考虑一下代码:
procedure DoSmthSecret;
var
Seed: array[0..31] of Byte;
begin
// get random seed
..
// use the seed to do something secret
..
// erase the seed
FillChar(Seed, SizeOf(Seed), 0);
end;
Run Code Online (Sandbox Code Playgroud)
代码的问题是:FillChar是编译器内在的,并且编译器可能会"优化它".问题是C/C++编译器所知,请参阅SecureZeroMemory.现代Pascal编译器(Delphi,FPC)可以进行这样的优化,如果可以的话,它们是否提供了与SecureZeroMemory等效的?
我对拉撒路的自由帕斯卡做了一些工作.因此,当客户要求我为mac编写应用程序时,在最初之后,"它无法完成"阶段.(其次是asp.net可能是舞台)我想用lazarus写它.
问题是.我只有一台运行mac OSX的虚拟机,这意味着我真的不想在mac上开发.但是,我似乎无法获得我在Windows上的lazarus中编写的应用程序在Mac上工作.我已尝试使用Lazarus Wiki进行部署,并且MACOS文件夹为空,因此当我将其放在mac上时,它不会运行应用程序.
这样做的最佳方式是什么,还是我咆哮错误的树?
我正在尝试调试64位程序,但gdb似乎认为它具有i386体系结构。
# file /usr/local/bin/foo
/usr/local/bin/foo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.4.0, not stripped
# gdb --args foo bar
GNU gdb (GDB) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB …Run Code Online (Sandbox Code Playgroud) 我一直在学习Pascal(使用Free Pascal编译器)一个星期,并且遇到了一个看似简单的练习.给定如下所示的结构,找到最大加权分支:
1
4 9
7 0 2
4 8 6 3
Run Code Online (Sandbox Code Playgroud)
分支是从顶部开始的任何数字序列(在这种情况下:1),对于每个数字,分支可以向左或向右扩展.例如,分支1-4-0可以扩展为1-4-0-8或1-4-0-6.所有分支必须从顶部开始,在底部结束.
在这个例子中,最大分支是1-4-7-8,这给了我们20.为了解决这个问题,我尝试使用回溯.三角形结构存储在"三角形"类型的数组中:
type triangle = array[1..MAX_NUM_OF_ROWS, 1..MAX_NUM_OF_ROWS] of integer;
Run Code Online (Sandbox Code Playgroud)
这是我的实现:
function findAux(data: triangle; dim: integer; i: integer; j:integer) : integer;
begin
if i = dim then
findAux := data[i][j]
else
if findAux(data, dim, i + 1, j + 1) > findAux(data, dim, i + 1, j) then
findAux := data[i+1][j+1] + findAux(data, dim, i + 1, j + 1);
else
findAux := data[i+1][j] + findAux(data, dim, i + …Run Code Online (Sandbox Code Playgroud)