AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[delphi](coding)

Martin Hope
user2580203
Asked: 2025-04-30 03:23:29 +0800 CST

在 Delphi TPrintDialog 中,可以通过编程设置打印机名称和纸张尺寸吗?

  • 5

使用 Delphi VCL。当用户开始打印作业时,我会显示 TPrintDialog。

理想情况下,打印对话框应该显示用户上次使用的打印机名称、纸张尺寸和方向(我已保存)。但是,虽然我可以将方向传递给打印机并使其显示在对话框中,但我找不到让对话框显示默认打印机和纸张尺寸以外的任何内容的方法。

我可以设计一个看起来像打印对话框的自定义对话框,并以这种方式传递参数,但似乎应该有一种方法将这些参数传递给 TPrintDialog。

谢谢。

斯科特

好的,我不确定从 StackOverflow 的角度来看我是否正确地执行了此操作,如果没有,请原谅。

在 Remy 的帮助下,我已经解决了 VCL 工作的问题,但现在我仍停留在 FMX MacOS 版本上。

使用页面方向,我可以成功设置和获取方向,但它不会影响页面设置对话框中的方向或页面的实际打印方式。

以下是我所拥有的:

function getOrientation: string;
var
FPrintInfo: NSPrintInfo;
orientation: integer;
begin
result:='';
FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo);
FPrintInfo.retain;
PMGetOrientation(FPrintInfo.PMPageFormat, @orientation);
FPrintInfo.release;
if (orientation=1) or (orientation=3) then result:='portrait';
if (orientation=2) or (orientation=4) then result:='landscape';
end;

procedure setOrientation (const toSetS:string);
var
FPrintInfo: NSPrintInfo;
orientation: integer;
begin
if toSetS='portrait' then orientation:=1 else orientation:=2;
FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo);
FPrintInfo.retain;
PMSetOrientation(FPrintInfo.PMPageFormat,orientation,true);
FPrintInfo.release;
end;

谢谢。

delphi
  • 1 个回答
  • 56 Views
Martin Hope
Ross
Asked: 2025-04-21 14:10:44 +0800 CST

快速 Delphi ASM ASCII 字符串比较可选忽略第一个字符

  • 7

我希望有汇编语言经验的人能帮我写一个 Delphi 函数,如果字符串以 Chr(127) 开头,则忽略该字符串的第一个字符。这个函数用于排序比较,当比较 30,000 个条目时,由于必须在比较之前从第二个字符复制文本,因此速度非常慢。这是原始函数。

function CompareText(const S1, S2: string): Integer; assembler;
asm
        PUSH    ESI
        PUSH    EDI
        PUSH    EBX
        MOV     ESI,EAX
        MOV     EDI,EDX
        OR      EAX,EAX
        JE      @@0
        MOV     EAX,[EAX-4]
@@0:    OR      EDX,EDX
        JE      @@1
        MOV     EDX,[EDX-4]
@@1:    MOV     ECX,EAX
        CMP     ECX,EDX
        JBE     @@2
        MOV     ECX,EDX
@@2:    CMP     ECX,ECX
@@3:    REPE    CMPSB
        JE      @@6
        MOV     BL,BYTE PTR [ESI-1]
        CMP     BL,'a'
        JB      @@4
        CMP     BL,'z'
        JA      @@4
        SUB     BL,20H
@@4:    MOV     BH,BYTE PTR [EDI-1]
        CMP     BH,'a'
        JB      @@5
        CMP     BH,'z'
        JA      @@5
        SUB     BH,20H
@@5:    CMP     BL,BH
        JE      @@3
        MOVZX   EAX,BL
        MOVZX   EDX,BH
@@6:    SUB     EAX,EDX
        POP     EBX
        POP     EDI
        POP     ESI
end;

如果您能帮忙的话非常感谢。

delphi
  • 1 个回答
  • 174 Views
Martin Hope
GuidoG
Asked: 2025-04-03 15:17:07 +0800 CST

如何将可空整数设置为空?

  • 6

我已经创建了一个像这样的可空类型,这是我在 SO 答案中发现的,不记得是哪一个了。

unit NullableType;

interface

uses
  System.SysUtils, System.Rtti;

type
  TNullable<T> = record
 private
    FValue: T;
    FHasValue: IInterface;
    function GetHasValue: Boolean;
    function GetValue: T;
    procedure SetValue(const AValue: T);
  public
    constructor Create(AValue: T);
    function ToString: string; // <-- add this for easier use!
    property HasValue: Boolean read GetHasValue;
    property Value: T read GetValue write SetValue;
  end;


implementation


constructor TNullable<T>.Create(AValue: T);
begin
   SetValue(AValue);
end;

function TNullable<T>.GetHasValue: Boolean;
begin
  Result := FHasValue <> nil;
end;

function TNullable<T>.GetValue: T;
begin
  if HasValue then
    Result := FValue
  else
    Result := Default(T);
end;

procedure TNullable<T>.SetValue(const AValue: T);
begin
  FValue := AValue;
  FHasValue := TInterfacedObject.Create;
end;

function TNullable<T>.ToString: string;
begin
  if HasValue then
  begin
    if TypeInfo(T) = TypeInfo(TDateTime) then
      Result := DateTimeToStr(PDateTime(@FValue)^)
    else if TypeInfo(T) = TypeInfo(TDate) then
      Result := DateToStr(PDateTime(@FValue)^)
    else if TypeInfo(T) = TypeInfo(TTime) then
      Result := TimeToStr(PDateTime(@FValue)^)
    else
      Result := TValue.From<T>(FValue).ToString;
  end
  else
    Result := 'null';
end;

end.

我的问题是我不知道如何将其设置为空。
例如

var
  id : TNullable<integer>;
begin
  if Edit1.Text <> '' then
    id.Value := StrToInt(Edit1.Text)
  else
    id.Value := null;  // runtime error

这给了我运行时错误

无法将类型 (Null) 的变量转换为类型 (Integer)

我已经有一段时间没有用 Delphi 编程了,我就是搞不清楚如何设置id变量的值null

id.Value := nil;

给出编译器错误

不兼容的类型:“整数”和“指针”

只有不设置 的值,id我才能获得它的值null,但如果我想将其设置为任何值,包括 null ,该怎么办?怎么做?

delphi
  • 2 个回答
  • 120 Views
Martin Hope
GuidoG
Asked: 2025-03-29 18:56:12 +0800 CST

如何使用 SHA256 对 Delphi 字符串进行哈希处理以匹配 C# 中的哈希?

  • 8

在 C# 中,我们有这个函数:

public string GetStringSha256Hash(string text, Encoding coding)
{
    string result = "";
    if (text != null)
    {
        using (SHA256 sHA256Managed = SHA256.Create())
        {
            byte[] bytes = coding.GetBytes(text);
            byte[] array = sHA256Managed.ComputeHash(bytes);
            result = BitConverter.ToString(array).Replace("-", string.Empty);
        }
    }
     return result;
}

我尝试在 Delphi 中执行相同操作,但得到的结果却不同。

就像这样简单的事情:

Result := THashSHA2.GetHashString(Text);

返回不同的结果。

我怀疑是因为在 C# 中我们总是使用 UTF-8,但我找不到如何在 Delphi 中使用编码。

我尝试过这个:

var
  Hash: TIdHashSHA256;
begin
  Hash := TIdHashSHA256.Create;

  try
    SHA256Hash := Hash.HashString(Text, TEncoding.UTF8);

但它给出了一个编译错误

[dcc32 错误] Unit1.pas(216): E2010 不兼容类型:“IIdTextEncoding”和“TEncoding”

在 Delphi 中执行此操作的正确方法是什么?

该值在 C# 中12345返回,但在 Delphi 中却返回。1445217533E7D4D0CFFD9109C4EDB60D62A02C0F0DE9537BE44F5E00D348EB4F5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5

我希望 Delphi 版本返回与 C# 版本相同的值。

delphi
  • 1 个回答
  • 145 Views
Martin Hope
Richard Shuck
Asked: 2025-03-23 02:40:38 +0800 CST

从 TRTTIMethod 获取 ClassType

  • 7

仅给定一个TRttiMethod,是否有可能找到定义类?

我在基类中定义了一个类过程,当我在派生类中搜索方法时,它会显示出来。我可以调用它,但是我想找出实际定义该方法的基类的名称,而不是派生类的名称。

TRttiMethod关于 classtype 等的所有属性都返回TRttiMethod自己的定义,而不是实现类的定义。

TBase = class
public
  class procedure Write;
end;

THigher = class(TBase);

var Context:=TRttiContext.Create;
var T:=Context.GetType(THigher);
var Method: TRttiMethod:=nil;
for var Item in T.GetMethods('Write') do
  if (Item.MethodKind=TMethodKind.mkClassProcedure) then
  begin
    Method:=Item;
    // How to get TBase from Method ?
    break;
  end;
delphi
  • 1 个回答
  • 81 Views
Martin Hope
Matthias B
Asked: 2025-03-10 02:55:48 +0800 CST

为什么如果将动态数组放在记录或类中,它会变成不兼容的类型?

  • 6

为什么当将动态放置在记录或类中时,它会array of string变得与其他动态不兼容?array of string

type
  TRec = record
    ArrayInRecord: array of string;
  end;

var
  Rec: TRec;
  SimpleArray1, SimpleArray2, CombinedArrayOK, CombinedArrayFail: array of string;

begin
  SimpleArray1 := ['1', '2'];
  SimpleArray2 := ['3', '4'];
  CombinedArrayOK := SimpleArray1 + SimpleArray2;  // No problem here

  Rec.ArrayInRecord := ['5', '6'];
  CombinedArrayFail := SimpleArray1 + Rec.ArrayInRecord;  // E2008 Incompatible types
end;
delphi
  • 1 个回答
  • 38 Views
Martin Hope
Tom
Asked: 2025-03-03 01:44:44 +0800 CST

如何阻止 DLL 中的 WriteLn()?

  • 5

我有一个 DLL(来自libJasPer 项目)。当我通过控制台应用程序解码图像时,jas_image_decode()该 DLL 在 STDOUT 上显示警告。

我在 JasPer 中查找了如何禁用警告,但一无所获。如何在 Delphi/Lazarus 中阻止它?

delphi
  • 1 个回答
  • 117 Views
Martin Hope
Shaun Roselt
Asked: 2025-02-10 09:29:28 +0800 CST

如何在FMX中动态创建具有圆角的TRectangle?

  • 5

我知道这很简单,但我只是不知道为什么我的TRectangle没有圆角。

这是我的代码:

var Box2 := TRectangle.Create(Application);
Box2.Parent := Form1;
Box2.Position.X := 300;
Box2.Position.Y := 256;
Box2.Width := 177;
Box2.Height := 50;
Box2.Stroke.Thickness := 10;
Box2.XRadius := 10;
Box2.XRadius := 10;
Box2.Name := 'Whatever2';

它看起来是这样的:

Delphi 中的 TRectangle

这就是我需要的样子:

Delphi 中的 TRectangle


为了显示圆角,我的代码中缺少什么?

delphi
  • 1 个回答
  • 51 Views
Martin Hope
Anton Larin
Asked: 2025-02-10 04:08:02 +0800 CST

如果项目没有平台,请跳过该组

  • 7

我有一个 Delphi 10.3 项目组。其中的所有项目都具有 Win32 目标平台,只有其中一部分具有 Win64 目标平台。当我使用 MSBuild 以 /p:Platform=Win32 构建该组时,所有项目都已构建。但如果使用 /p:Platform=Win64 键执行相同操作,则所有项目也都已构建,即使它们未配置 Win64 目标平台。

如何避免为那些在构建项目组期间没有该目标的项目构建 Win64 目标?

delphi
  • 1 个回答
  • 61 Views
Martin Hope
Franz
Asked: 2025-01-22 20:07:59 +0800 CST

在 1 个项目中使用 Delphi 10.4. 和 12.2

  • 4

我必须合作一个软件项目,其中 1 名团队成员使用 Delphi 12.2,而其他一些团队成员仍使用 Delphi 10.4。

通过 Git repos 交换源代码现在产生了一些不兼容性,因为在使用旧版本的 Delphi 编译器打开源代码时发生了一些新错误:

ECustomStyleException 样式错误:未找到值

将不同版本 Delphi 编译器一起使用的最佳解决方案是什么?

是否有工具可以根据需求删除此新功能?

delphi
  • 2 个回答
  • 58 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve