我在Delphi中制作看起来像Paint的东西.我找到了如何制作缩放功能:
procedure SetCanvasZoomFactor(Canvas: TCanvas; AZoomFactor: Integer);
var
i: Integer;
begin
if AZoomFactor = 100 then
SetMapMode(Canvas.Handle, MM_TEXT)
else
begin
SetMapMode(Canvas.Handle, MM_ISOTROPIC);
SetWindowExtEx(Canvas.Handle, AZoomFactor, AZoomFactor, nil);
SetViewportExtEx(Canvas.Handle, 100, 100, nil);
end;
end;
procedure TMainForm.btnZoomPlusClick(Sender: TObject);
var
bitmap: TBitmap;
begin
bitmap := TBitmap.Create;
if(zoomVal < 1000) then
zoomVal:=zoomVal+zoomConst; //zoomVal = 100 by default; zoomConst = 150;
try
bitmap.Assign(MainForm.imgMain.Picture.Bitmap);
SetCanvasZoomFactor(bitmap.Canvas, zoomVal);
Canvas.Draw(MainForm.imgMain.Left,MainForm.imgMain.Top, bitmap);
finally
bitmap.Free
end;
end;
Run Code Online (Sandbox Code Playgroud)
但是,问题是 - 它仅缩放图像的左上区域.
缩放前的示例:
放大后:

我希望能够在缩放后移动所有图片区域.我该怎么做?
在Qt中有类似Form.onChangeDelphi的东西吗?
我找到了一些changeEvent方法,但是当我写连接时
connect(this, SIGNAL(this->changeEvent),this, SLOT(checkIfSomethingChanged()));
并尝试检查它
void importdb_module::checkIfSomethingChanged(){
QMessageBox::information(0, "", "Test");
}
Run Code Online (Sandbox Code Playgroud)
我意识到它不起作用.
每当我的表格发生变化时,我想检查一些情况,怎么做?
我需要从服务器向客户端发送动态对象数组.一个例子作为数组,它将类的对象Figure与其坐标,颜色等信息结合在一起.
我试图使用这样的东西来发送数据:
for i := 0 to ServerSocket.Socket.ActiveConnections - 1 do
begin
ServerSocket.Socket.Connections[i].SendText(some values); // then parsing this text to get values
end;
Run Code Online (Sandbox Code Playgroud)
但是我觉得这样做真的很糟糕.那么,拜托,您能告诉我如何发送和接收某些对象的数组(使用IdTCPClient/Server或Client/ServerSockets)的正确方法吗?
如何使用QODBC/QODBC3 Qt驱动程序正确连接到Excel文件?
在第一次我建了这样的驱动程序(cmd)
> cd%QTPATH%\ src\plugins\sqldrivers\odbc
> qmake odbc.pro
> NMAKE
然后qsqlodbc4.dll创建了文件 %QTPATH%\plugins\sqldrivers
我用过这段代码
#include <QApplication>
#include <QtGui>
#include <QtSql>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
//QComboBox myCombo;
//excel stuff
QSqlDatabase dbExcel = QSqlDatabase::addDatabase("QODBC","dbExcel");
// i thought mayde that would work
// dbExcel.setDatabaseName("C:\databases\test.xlsx");
//i tried connection string too
dbExcel.setDatabaseName(QString("DRIVER={Microsoft Excel Driver (*.xlsx)}; READONLY=FALSE; FIL={MS Excel}; DBQ=C:\databases\test.xlsx"));
if(!dbExcel.open())
{
QSqlError er = dbExcel.lastError();
QMessageBox::information(0, "Error", er.text());
}
//...................
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
在那里我把那个错误(它翻译成:
[Microsoft][ODBC driver manager] Data …Run Code Online (Sandbox Code Playgroud) 我发现有关如何创建delphi组件的教程很不错,但是他们只使用现有组件之一作为对象来继承动作.像这样的东西
unit CountBtn;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TCountBtn = class(TButton)
private
FCount: integer;
protected
procedure Click;override;
public
procedure ShowCount;
published
property Count:integer read FCount write FCount;
constructor Create(aowner:Tcomponent); override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Mihan Components', [TCountBtn]);
end;
constructor TCountBtn.Create(aowner:Tcomponent);
begin
inherited create(Aowner);
end;
procedure Tcountbtn.Click;
begin
inherited click;
FCount:=FCount+1;
end;
procedure TCountBtn.ShowCount;
begin
Showmessage('On button '+ caption+' you clicked: '+inttostr(FCount)+' times');
end;
end.
Run Code Online (Sandbox Code Playgroud)
但是,如果我需要使用少量元素的组件,我该怎么办?让我们说,我得到了Button和Edit田地.然后在按钮上单击编辑字段中的文本应与按钮上的文本相同.我开始像这样做,但似乎它不会像我想的那样工作: …
我正在努力取得进步.在服务器端,我创建了一个控制器,它应该获取进度值并将值存储在会话中.
在客户端,我创建了两个ajax请求.其中一个启动一个函数,我想监视它,另一个只是检查进度阶段.我的意思是,这就是我认为它会起作用的方式.但它只会在完成后输出一些东西.
它只是等待几秒钟然后警告"完成!" 就这样.
有什么问题?也许我应该在控制器中创建新线程来监控进度阶段?
这是客户端代码:
function generate() {
setTimeout(checkProgress, 400);
$.ajax({
type: "POST",
url: "/PPTReport/Generate",
async: true,
success: function (text) {
console.log(text);
},
error:function() {
console.log("error! error!");
}
});
}
function checkProgress() {
var id = "reportProgress";
$.ajax({
type: "POST",
url: "/PPTReport/GetProgress",
async: true,
data: "id="+id,
success: function (data) {
if (data.done) {
console.log('Done!');
} else {
console.log('Progress at ' + data.percent + '%');
console.log(data.percent);
setTimeout(checkProgress, 100 );
}
},
error: function() {
console.log('ajax error');
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是服务器端代码 …
这是我的客户端请求代码:
import request from 'axios';
//...
let url = 'Login/SignIn',
headers = {
headers: {
'Content-Type': 'application/json'
}
},
data = JSON.stringify( {
name: 'danil',
password: 'pwd'
});
request.post(url, data, headers);
Run Code Online (Sandbox Code Playgroud)
乍一看还不错。
但这一切都在我的控制器中结束了:
这是代码顺便说一句:
[HttpPost]
public async Task<ActionResult> SignIn([FromBody]string name, [FromBody]string password)
{
var userLoginCommand = new UserLogInCommand {
Login = name,
Password = password
};
await _dispatcher.DispatchAsync(userLoginCommand);
return Content(userLoginCommand.Result, "application/json");
}
Run Code Online (Sandbox Code Playgroud)
它出什么问题了?我忘记了什么?
我尝试JSON.stringify通过添加和删除来尝试,尝试不发送标头(然后抛出415 error)但没有更改。仍然有空值。
UPD:正如阿里在评论中建议的那样,如果我们LoginModel像这样使用它,传递数据就可以了:
public class LoginModel
{
public string …Run Code Online (Sandbox Code Playgroud) 为什么当它进入ECX的循环时,有一些大的随机值为0?还有其他方法可以在这里制作循环吗?
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
function FPUTest(a:Double):Double;
asm
FINIT
FLD a
MOV ecx,0
@cycle:
FADD st(0), st(0)
loop @cycle
end;
var a:Integer;
begin
readln(a);
Writeln(FPUTest(a));
end
Run Code Online (Sandbox Code Playgroud)
.
我写了这样的模块来存储我的绘图应用程序中的图片的最后更改"在Delphi中
unit HistoryQueue;
interface
uses
Graphics;
type
myHistory = class
constructor Create(Size:Integer);
public
procedure Push(Bmp:TBitmap);
function Pop():TBitmap;
procedure Clean();
procedure Offset();
function isEmpty():boolean;
function isFull():boolean;
function getLast():TBitmap;
protected
historyQueueArray: array of TBitmap;
historyIndex, hSize:Integer;
end;
implementation
procedure myHistory.Push(Bmp:TBitmap);
var tbmp:TBitmap;
begin
if(not isFull) then begin
Inc(historyIndex);
historyQueueArray[historyIndex]:=TBitmap.Create;
historyQueueArray[historyIndex].Assign(bmp);
end else begin
Offset();
historyQueueArray[historyIndex]:=TBitmap.Create;
historyQueueArray[historyIndex].Assign(bmp);
end;
end;
procedure myHistory.Clean;
var i:Integer;
begin
{ for i:=0 to hSize do begin
historyQueueArray[i].Free;
historyQueueArray[i].Destroy;
end; }
end;
constructor myHistory.Create(Size:Integer);
begin
hSize:=Size;
SetLength(historyQueueArray, hSize);
historyIndex:=-1; …Run Code Online (Sandbox Code Playgroud) 当我重构一些旧的 C# 代码以使用该库生成文档时Office.Interop,我发现了这一点,因为它使用了 UI 上下文。当从它调用函数时它会阻塞它
例如:
private void btnFooClick(object sender, EventArgs e)
{
bool documentGenerated = chckBox.Checked ? updateDoc() : newDoc();
if(documentGenerated){
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
我决定更改它以减少阻塞 UI:
private async void btnFooClick(object sender, EventArgs e)
{
bool documentGenerated; = chckBox.Checked ? updateDoc() : newDoc();
if(chckBox.Checked)
{
documentGenerated = await Task.Run(() => updateDoc()).ConfigureAwait(false);
}
else
{
documentGenerated = await Task.Run(() => newDoc()).ConfigureAwait(false);
}
if(documentGenerated){
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
它抛出了这个错误:
Current thread must be set to single thread apartment (STA) …Run Code Online (Sandbox Code Playgroud)